测试程序"Cannot find symbol"



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

public class Account {
// Declarations
String Number = "null";
String Type = "null";
String Card = "null";
String Date = "null";
protected Account() {
}
public String toString() {
    return "nt Your account number is " + Number + ",your account type is " + Type + ",your card number is " + Card
            + ".nt 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;
}  }

和AccountTester.java

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
            + "nn");
    // 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);
} }

第一个代码没有问题,但是在该行的第二个代码中说

"Account a = new Account();"

它显示了一个错误,说"找不到符号,符号类帐户,位置class counchtester"。我尝试将其更改为

"AccountTester a = new Account();"

,但它不仅没有修复它,而且还制作了所有代码" a.set"给出相同的"找不到符号"错误。我该如何修复此

您正在创建一个模型,并且要导入模型POJO Account在您创建类的包装的其他包装中使用的其他Java类中使用。如果是这样,请将所有protected方法更改为public方法。那是因为当您导入班级然后构造时。Java无法创建您的模型,因为在运行时没有访问权限。请更改。这是更多信息的链接。

链接

要上班,它必须在同一包中!

我希望帮助您!

最新更新