• 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

a fatal Exception about "NoClassDefFoundError"

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[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
 
Wang Kaiyi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic