首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tester程序的“找不到符号”

tester程序的“找不到符号”
EN

Stack Overflow用户
提问于 2018-02-20 12:33:11
回答 1查看 51关注 0票数 0

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

代码语言:javascript
复制
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;
}  }

和AccountTester.java

代码语言:javascript
复制
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);

} }

第一个代码没有问题,但是在第二行代码中写道

代码语言:javascript
复制
"Account a = new Account();"

它显示一条错误消息“找不到symbol,symbol类Account,location类accountTester”。我试着把它改成

代码语言:javascript
复制
"AccountTester a = new Account();"

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

EN

回答 1

Stack Overflow用户

发布于 2018-02-20 12:44:33

您正在创建一个模型,并且希望导入您的模型POJO Account,以便在创建该类的包的不同包中的另一个java类中使用。如果是这样,请将您所有的protected方法更改为public方法。这是因为当你导入类然后构造它的时候。Java无法创建您的模型,因为在运行时没有访问权限。请把它换掉。这里有一个更多信息的链接。

link

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

我希望能帮助你!!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48877893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档