My Eclipse (Indigo) was running just fine. I created a simple class Hello
. It is placed in package cont
in the folder ch13
. However, when I try to run it from Eclipse I get info from Java Virtual Machine Launcher:
Could not find the main class: cont.Hello.
I tried to run other classes from this package and they run just fine (that is the classes that existed there before). However any new class I create in this package has these problems. Actually any new class I create in Eclipse runs into this problems. I decided to check how it works from the command line. It seems that the problem still exist - I get same error. I checked the path and it is C:\Program Files\Java\jdk1.7.0_02\bin
, which is correct (note the other classes are running from Eclipse just fine). I tried to run with java -cp . Hello
and there are some Errors produced starting with java.lang.NoClassDefFoundError: Hello (wrong name: cont/Hello)
. Code itself is simple:
package cont; public class Hello { public static void main(String[] args){ System.out.println("Hello"); } }
How can I fix it so that my classes still run under Eclipse?
Reasons to Occur Error The error generates because the JVM fails to load the main class or package name. There are some other reasons that generate the same error, as follows: The class has been declared in the wrong package. Dependencies missing from the CLASSPATH.
In the Main tab, make sure that the "Main class:" is set to quickstart. Main . Eclipse should have identified this for you; if not, click Search... and select the class.
.metadata
is corrupted.
Steps:
Warning: Deleting .metadata will delete all your Eclipse configurations, plugins, project setups. Make a backup before you attempt this!
Stop eclipse, delete .metadata in workspace and restart eclipse
Import Project
Run again
Sometimes I have a similar problems in some pre-release versions of eclipse. For fix the error, I delete the Run Configuration. You can find that in menu Run, Run Configurations...
Then I launch the app with Alt+Shift+X, then J. If this don't work, Ctrl+F11.
.metadata
directoryIn another way, the configuration settings for your current workspace may are corrupted. Those settings are in the .metadata
directory in your current workspace 1. In that case, there is no other choice than delete the directory:
.metadata
directory.Notes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With