Reputation: 21
This program should tell me if it can find the file I am naming. Eclipse has no red lines but every time I run it I get this error message and I don't know why. Thank you in advance for any help you can provide.
import java.io.File;
public class StockMarket {
public StockMarket(String[] args) {
ReadFiles r = new ReadFiles();
System.out.println(r.checkIsFile());
}
}
and the second class
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();
}
}
Error Message:
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)
Upvotes: 0
Views: 6963
Reputation: 2228
System.out.println(r.checkIsFile());
should be in the static main function, you are going the wrong way for the flow of code...
Upvotes: 0
Reputation: 3523
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.
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.
Upvotes: 2