我有2个文件,tweet.java和Account.java。当我编译tweet.java时,它会通过,但是当我编译Account.java时它会说这个错误
C:\Users\Nolan\Documents\OBJECTP\Java\tweet>javac tweet.java
C:\Users\Nolan\Documents\OBJECTP\Java\tweet>javac Account.java
Account.java:8: error: cannot find symbol
private tweet[] UserTweets;
^
symbol: class tweet
location: class Account
Account.java:10: error: cannot find symbol
private final tweet[] EMPTY_TWEET;
^
symbol: class tweet
location: class Account
Account.java:17: error: cannot find symbol
this.UserTweets = new tweet[20];
^
symbol: class tweet
location: class Account
Account.java:18: error: cannot find symbol
this.EMPTY_TWEET = new tweet[0];
^
symbol: class tweet
location: class Account
Account.java:38: error: cannot find symbol
this.UserTweets[TweetCount] = new tweet(message);
^
symbol: class tweet
location: class Account
5 errors
我问过我的教授和很多朋友,他们不知道问题是什么!我在这边缘,因为我必须使用来自我大学实验室的编译器(显然它在我编译时可以工作)。
我会剪切源代码中的方法来缩短它。
tweet.java文件:
//tweet.java
import java.util.Calendar;
public class tweet {
private String message;
private int D;
private int M;
private int Y;
private int H;
private Calendar now;
private int Min;
public tweet(String Mes){
this.message=Mes;
this.now=Calendar.getInstance();
this.D=now.get(Calendar.DATE)+1;
this.M=now.get(Calendar.MONTH);
this.Y=now.get(Calendar.YEAR);
this.H=now.get(Calendar.HOUR);
this.Min=now.get(Calendar.MINUTE);
}
//Method's here
}
Account.java文件:
//Account.java file
import java.util.Calendar;
public class Account {
private String Username;
private String Password;
private String FirstName;
private String LastName;
private tweet[] UserTweets;
private int TweetCount;
private final tweet[] EMPTY_TWEET;
public Account(String UserName,String Password,String FName,String LName){
this.Username=UserName;
this.Password=Password;
this.FirstName=FName;
this.LastName=LName;
this.UserTweets = new tweet[20];
this.EMPTY_TWEET = new tweet[0];
this.TweetCount=0;
}
//Method's here
}
你能帮帮我吗?
答案 0 :(得分:0)
虽然您已将它们放在同一目录中,但这两个类彼此无法访问。您需要在Account类中导入tweet或更好地创建一个包并将两个类放入其中。
package com
import java.util.Calendar;
公共课推文{ ///
}
package com
// Account.java文件
import java.util.Calendar;
公共类帐户{
//
}
避免将您的类放在默认包中以获得更好的命名空间