• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoClassDefFoundError

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, my program have been compiled but when I try to run it, the computer show me following error. Could anybody please help me to solve this problem?
Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name:
/sourceforge/transmogrify/symtab/Main)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.jav
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This error is telling you that you that the Java Virtual Machine cannot find the class you are trying to run. The �wrong name� portion of the message indicates you are not properly identifying your class when trying to run it because it is part of a package. This is something that many beginners have a some trouble with.
Take a look at the following class:

Notice that class is part of the package �com.foo�. If I try to run this class with the com\foo directory as my classpath entry, I will get a similar error as you are getting:

On my system, as most systems, my system�s classpath has an entry of . (just a dot) which means current directory. So if I do the following, I get the same error since the working directory of �D:\Dev\Misc\com\foo\� becomes part of my classpath:

The reason is that the full and proper name of the class is not �MyClass� but rather �com.foo.MyClass�. Therefore I need to identify it as such, and have the directory that contains the package, not the class, in my classpath:

Or if I rely on my system�s classpath entry to leverage the current working directory:

Lastly, as a side note, instead of identifying the (full name of the) class with dot notation, you can use also use forward slashes (not the backslashes that Windows uses) like this:

However, the dot notation is more standard and generally preferred (and just makes more sense since the true name of the class is �com.foo.MyClass� and not �com/foo/MyClass�.
For some more information and guidance, take a look at the How To Set The Classpath article in the Java Beginners Faq section of JavaRanch's Frequently Asked Questions page. Also look at Your First Cup of Java on the Sun Tutorial.
For more information on packages look at the Interfaces and Packages lesson on the Sun Tutorial Site.
[ January 24, 2004: Message edited by: Mark Vender ]
 
songtao zhang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very very much, you are so cool! I solved the problem according to your message, It have confused me for two days.
songtao
reply
    Bookmark Topic Watch Topic
  • New Topic