• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError with packages  RSS feed

 
rick sowfilk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there

the following code compile and throws runtime Error exception NoClassDefFoundError



compile :
C:\test_app>javac main_code.java


run :
C:\test_app>java main_code
Exception in thread "main" java.lang.NoClassDefFoundError: main_code (wrong name: test_app/main_code)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)


but if i try to run the same code without
package test_app;
then it runs correctly.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have the package statement in your program, make sure the directory that is the name of your package is in your CLASSPATH, and then run the program with java test_app.main_code
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!