我应该做两个相关的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 "\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
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);
} }第一个代码没有问题,但是在第二行代码中写道
"Account a = new Account();"它显示一条错误消息“找不到symbol,symbol类Account,location类accountTester”。我试着把它改成
"AccountTester a = new Account();"但它不仅没有修复它,而且还使所有带有"a.set“的代码都发出了相同的”找不到符号“错误。我该如何解决这个问题呢?
发布于 2018-02-20 12:44:33
您正在创建一个模型,并且希望导入您的模型POJO Account,以便在创建该类的包的不同包中的另一个java类中使用。如果是这样,请将您所有的protected方法更改为public方法。这是因为当你导入类然后构造它的时候。Java无法创建您的模型,因为在运行时没有访问权限。请把它换掉。这里有一个更多信息的链接。
要工作,它必须在同一个包中!!
我希望能帮助你!!
https://stackoverflow.com/questions/48877893
复制相似问题