Reputation: 1028
I am working with Eclipse and I've been doing it since several months ago without any problem. Now I've created a new class in a certain package, but Eclipse does not compile it. So I tried to create a new simple class:
public class Test {
public static void main(String[] args) {
System.out.println("Hello");
}
}
But I get always this error:
Errore: impossibile trovare o caricare la classe principale Test (Error: impossible to find or load main class Test)
I compiled it with cmd: in that case, Eclipse can run the java file, but it can't create the .class file with new edits; it just launches the last version of the compiled file.
I tried to uninstall and reinstall Eclipse, but still got this problem.
Upvotes: 1
Views: 1083
Reputation: 1028
I solved by deleting everything I had on Eclipse, but when I opened a new Eclipse it gave me the error. So I created new projects, by importing one by one the single java files, then it worked.
Upvotes: 0
Reputation: 2231
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
Original Source of this answer
Upvotes: 2