aspose file tools*
The moose likes Java in General and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic
Author

NoClassDefFoundError

songtao zhang
Greenhorn

Joined: Jan 24, 2004
Posts: 6
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)
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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

Joined: Jan 24, 2004
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFoundError
 
Similar Threads
JBOSS PROBBLEM...PLEASE HELP ME!!!
Transmogrify
Installing JDK
help !!
please help running programs created in jsdk 1.4 into jsdk 1.6