Monday, January 27, 2014

Eclipse : Caused by: java.lang.ClassNotFoundException / Exception in thread "main"

java.lang.NoClassDefFoundError: com/javaxp/test
Caused by: java.lang.ClassNotFoundException: com.javaxp.Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Exception in thread "main" 


There could be a couple of reasons for the above error

1. .class files not created properly

Try
Project -> Clean -> Clean all projects / Clean project selected below -> OK

2. JVM is not able to pick the classpath

Try
right click on the project -> Properties -> Java Compiler -> unclick the first box saying 'Enable project specific settings' -> Apply -> OK

3. A missing JAR file in the classpath

Try
right click on the project -> Properties -> Java Build Path -> Libraries -> (Remove unwanted missing jar files if any) -> OK

Hope this helps in most of the cases.