0

这个程序应该告诉我它是否可以找到我命名的文件。Eclipse 没有红线,但每次我运行它时都会收到此错误消息,但我不知道为什么。提前感谢您提供的任何帮助。

import java.io.File;

public class StockMarket {
    public StockMarket(String[] args) {
        ReadFiles r = new ReadFiles();
        System.out.println(r.checkIsFile());
    }
}

和二等

import java.io.*; 
import java.util.StringTokenizer; 

public class ReadFiles {
    public static void main(String[] args) {
        System.out.println("Test");
        File file = new File("C:\\stocks\\yahoo.csv");
        int row = 0;
        String[] [] items;
    }

    public boolean checkIsFile() {
        File file= new File("C:\\stocks\\yahoo.csv");
        return file.isFile();
    }
}

错误信息:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
checkIsFile cannot be resolved or is not a field
    at StockMarket.main(StockMarket.java:6)
4

2 回答 2

2

A few things to try.

It looks like your ReadFiles class is not being compiled.

You might try adding an import statement for your ReadFiles class to your main.

Do a clean build.

Also be aware that occasionally Eclipse goes "weird" and you need to do some combination of close it reopen it and/or clean the workspace and/or reboot. I know you would think with modern software... but still it happens.

Here are a couple of links that may help.

Keeping Eclipse running clean

Restarting Eclipse Clean If You Cannot Run Eclipse From A Command Line (Mac OSX)

As an aside, on some prior projects and versions of eclipse I found myself having to do this so frequently that I ended up just setting up eclipse to always launch with the clean option.

于 2013-08-13T01:53:10.163 回答
0
System.out.println(r.checkIsFile());

应该在静态主函数中,你的代码流走错路了......

于 2016-04-15T07:09:23.057 回答