找不到另一个类文件的符号
我已经遇到过这个问题几次,我创建了另一个类文件,但主类文件找不到它。 这是主类文件:
package textfiles;
import java.io.IOException;
public class FileData
{
public static void main(String[] args)
{
String file_name = "Lines.txt";
try {
ReadFile file = new ReadFile(file_name);
String[] aryLines = file.OpenFile();
for(int i =0; i<aryLines.length; i++)
{
System.out.println(aryLines);
}
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
这是它找不到的类文件:
package textfiles;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
public class ReadFile
{
private String path;
int numberOfLines=0;
public ReadFile(String file_path)
{
path = file_path;
}
public String[] OpenFile() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
int numberOfLines = readLines();
String[] textData = new String[numberOfLines];
for(int i=0; i<numberOfLines; i++)
{
textData[i] = br.readLine();
}
br.close();
return textData;
}
int readLines() throws IOException
{
FileReader file_to_read = new FileReader(path);
BufferedReader bf = new BufferedReader(file_to_read);
String aLine;
while((aLine = bf.readLine()) != null)
{
numberOfLines++;
}
bf.close();
return numberOfLines;
}
}
我尝试运行 javac textfiles\ReadFile.java 和 javac textfiles\FileData.java 作为 这个。那是行不通的。我已确保已编译 ReadFile 并修复了其中的所有错误。 我得到的编译器错误是:
C:\Users\Liloka\Source>javac FileData.java
FileData.java:13: cannot find symbol
symbol : class ReadFile
location: class textfiles.FileData
ReadFile file = new ReadFile(file_name);
^
FileData.java:13: cannot find symbol
symbol : class ReadFile
location: class textfiles.FileData
ReadFile file = new ReadFile(file_name);
^
2 errors
我正在使用 notepad++ 和 .cmd,因此它不可能是 IDE 错误。 提前致谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保 java 文件全部位于
textfiles
目录中:并运行:
您的代码无需任何修改即可运行。我认为您是从错误的目录进行编译的:
将
FileData.java
移动到textfiles
目录。Make sure the java files are all in the
textfiles
directory:And run:
Your code works without any modification. I think you are compiling from a wrong directory:
Move the
FileData.java
to thetextfiles
directory.您必须编译主类使用的所有 java 文件。由于 FileData 使用 ReadFile,因此您也必须编译它。
你尝试过
还是
?
You have to compile all the java files used by your main class. As ReadFile is used by FileData you have to compile it too.
Did you tried
or
?
肯定和生成的类有冲突。
只需尝试删除所有已生成的类并再次构建项目即可。
There must be a conflict with generated classes.
Just try to remove all the classes that have been generated and build project again.