my dog learned polymorphism*
The moose likes Java in General and the fly likes a fatal Exception about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "a fatal Exception about "NoClassDefFoundError"" Watch "a fatal Exception about "NoClassDefFoundError"" New topic
Author

a fatal Exception about "NoClassDefFoundError"

Wang Kaiyi
Greenhorn

Joined: Feb 02, 2004
Posts: 9
Hi, all!
I meet with a fatal Exception which leads to "NoClassDefFoundError";I am suprised to its performance.I can hardly solve it.Can anybody help me?
the following is the process I do...
(DelayInform.java is my program)
[ken@test47 consumer]$ ls De*
Debug.class Debuglycra.class DelayInform.java
[ken@test47 consumer]$ ls De*
Debug.class Debuglycra.class DelayInform.java
[ken@test47 consumer]$ javac -target 1.3 -encoding GBK DelayInform.java
[ken@test47 consumer]$ ls De*
Debug.class Debuglycra.class DelayInform.class DelayInform.java
[ken@test47 consumer]$ java DelayInform
Exception in thread "main" java.lang.NoClassDefFoundError: DelayInform (wrong name: com/linktone/sms/consumer/DelayInform)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
[ken@test47 consumer]$ echo $0
-bash
[ken@test47 consumer]$ uname -a
Linux test47 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Exception in thread "main" java.lang.NoClassDefFoundError: DelayInform (wrong name: com/linktone/sms/consumer/DelayInform)

This line in your error means that you are in the wrong directory to start your DelayInform class. Change directories so that you are in the directory which contains your com directory and then start run your class using:
java com.linktone.sms.consumer.DelayInform

HTH
Nigel
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
[ken@test47 consumer]$ java DelayInform
Exception in thread "main" java.lang.NoClassDefFoundError: DelayInform (wrong name: com/linktone/sms/consumer/DelayInform)

It looks to me like you have declared class DelayInform to be in a package called com.linktone.sms.consumer.DelayInform, but when you try to run the program, you are not specifying the fully qualified class name. If you declare a class as belonging to a package, then to run it, you must use the fully qualified class name, like this:
$ java com.linktone.sms.consumer.DelayInform


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Wang Kaiyi
Greenhorn

Joined: Feb 02, 2004
Posts: 9
I have practiced what you advise me to do and succeed in execute my own program by "java com.linktone.sms.consumer.DelayInform".(my package is com.linktone.sms.consumer.)Now, I am confused about that I have set "/com/linktone/sms/consuer" in the CLASSPATH and export it.Why must I use "java com.linktone.sms.consumer.DelayInform" instead of "java DelayInform"?(In my eyes, "java DelayInform" is OK)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Wang Kaiyi:
(In my eyes, "java DelayInform" is OK)

Well, computers rarely care about anyone's opinion -- there's simply a right and a wrong way. In this case, the "java" tool wants a fully-qualified class name including the package name; that's just how it is designed.


[Jess in Action][AskingGoodQuestions]
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
What your colleagues are saying is absolutely correct:
1. The key line in the error message is this:
Exception in thread "main" java.lang.NoClassDefFoundError: DelayInform (wrong name: com/linktone/sms/consumer/DelayInform)
2. That line is saying that you're looking for class "DelayInform" in package
".com.linktone.sms.consumer".
3. There are several workarounds including:
a) Recompile "DelayInform.java" without the "package" statement
b) Physically move your DelayInform .class file into subdirectory com/linktone/
sms/consumer
c) Specify .com.linktone.sms.consumer in your "java" command line
... or ...
d) Make a .jar file that has a subdirectory com/linktone/sms/consume
containing your DelayInform.class file, then specify the .jar in your Java
command line or $CLASSPATH environment variable.


Paul M. Santa Maria, SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a fatal Exception about "NoClassDefFoundError"