gpt4 book ai didi

java - 在java中找不到符号,编译时两个.java文件都在同一个目录中

转载 作者:行者123 更新时间:2023-12-02 11:10:55 24 4
gpt4 key购买 nike

我有 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

我问过我的教授和很多 friend ,他们都不知道是什么问题!我在这里处于优势地位,因为我必须使用我大学实验室的编译器(显然当我编译它时它在那里工作)。

我将削减源代码中的方法以缩短它。

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
}

你能帮我么?

最佳答案

虽然你已经把它们放在同一个目录下,但是这两个类是不能互相访问的。你需要在 Account 类中导入 tweet 或者更好地创建一个包并将两个类都放在其中。

包com

导入 java.util.Calendar;

公共(public)类推文{
///

}

包com

//Account.java文件

导入 java.util.Calendar;

公共(public)类帐户{

//

}

避免使用将类放在默认包中以获得更好的命名空间

关于java - 在java中找不到符号,编译时两个.java文件都在同一个目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21782964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com