测试仪程序“找不到符号”

时间:2018-02-20 04:33:11

标签: java

我应该制作两个相关的java程序,Account.java

iu git init
iu git remote add origin '%env.gitFolder%'
iu git fetch
# ...

和AccountTester.java

public class Account {
// Declarations
String Number = "null";
String Type = "null";
String Card = "null";
String Date = "null";

protected Account() {

}

public String toString() {
    return "\n\t Your account number is " + Number + ",your account type is " + Type + ",your card number is " + Card
            + ".\n\t your expireation date is: " + Date;
}

protected String getNumber() {
    return Number;
}

protected void setNumber(String number) {
    this.Number = number;
}

protected String getType() {
    return Type;
}

protected void setType(String type) {
    this.Type = type;
}

protected String getCard() {
    return Card;
}

protected void setCard(String card) {
    this.Card = card;
}

protected String getDate() {
    return Date;
}

protected void setDate(String date) {
    this.Date = date;
}  }

第一个代码没有问题,但在第<2行代码

import java.util.Scanner;
public class AccountTester {
public static void main(String[] args) {
    // Create Objects
    Scanner s = new Scanner(System.in);
    Account a = new Account();

    // auto with nothing set
    System.out.print("Your account information is curently set to" + a
            + "\n\n");

    // set info for account
    System.out.print("Please, enter your account number: \t");
    a.setNumber(s.nextLine());
    System.out.print("Please, enter your account type: \t");
    a.setType(s.nextLine());
    System.out.print("Please, enter your card number: \t");
    a.setCard(s.nextLine());
    System.out.print("Please, enter your expire date: \t");
    a.setDate(s.nextLine());

    System.out.print(a);

} }

它显示错误“无法找到符号,符号类帐户,位置类accountTester”。 我尝试将其更改为

"Account a = new Account();"

但它不仅没有修复它,而且还使所有带有“a.set”的代码都给出了相同的“找不到符号”错误。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您正在创建模型,并且您希望将模型POJO Account导入到您创建类的包的不同包中的另一个Java类中。如果是这样,请将您的所有protected方法更改为public方法。那是因为当你导入类然后构造它时。 Java无法创建模型,因为在运行时无法访问。请改变它。这是一个链接以获取更多信息。

link

要工作,必须在同一个包装中!!

我希望能帮到你!!