找不到另一个类文件的符号 [英] Cannot Find Symbol for another class file

查看:140
本文介绍了找不到另一个类文件的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几次这个问题,我创建了另一个类文件,主类文件找不到它。
这是主类文件:

I've had this problem a few times, where I've created another class file and the main class file can't find it. Here's the main class file:

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并修复了所有的错误。
我得到的编译器错误是:

I've tried running javac textfiles\ReadFile.java and javac textfiles\FileData.java as a suggestion for this. That doesn't work. I've made sure I have compiled ReadFile and fixed all the errors there. The compiler error I get is:

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错误。
提前感谢!

I'm using notepad++and .cmd so it can't be an IDE error. Thanks in advance!

推荐答案

确保java文件都在 textfiles

Make sure the java files are all in the textfiles directory:

textfiles/FileData.java
textfiles/ReadFile.java

并执行:

javac textfiles/FileData.java textfiles/ReadFile.java 
java textfiles.FileData

您的代码无需任何修改即可正常工作。我认为你正在从一个错误的目录进行编译:

Your code works without any modification. I think you are compiling from a wrong directory:


C:\Users\Liloka\Source> javac FileData.java


C:\Users\Liloka\Source>javac FileData.java

FileData.java 移至 textfiles 目录。

Move the FileData.java to the textfiles directory.

这篇关于找不到另一个类文件的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆