• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

NoClassDefFoundError

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a few codes.

public class Hello{

public static void main( String args[] ){

System.out.println( "My test" );

}

}

then " javac Hello.java "

then " java Hello",
System throws out "Exception in thread "main" java.lang.NoClassDefFoundError: Hello"

In WindowsXp's cmd,I use "echo %classpath%" ,it returns:
"D:\Program Files\Java\jdk1.5.0_11\bin;D:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;D:\Program Files\Java\jdk1.5.0_11\jre\lib\rt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.5common\lib"

I suspected I set wrong classpath. Pls help me.
[ July 18, 2007: Message edited by: george zhao ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
use "java -cp . Hello"

with -cp option you are telling to JVM where to find your classes
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by george zhao:
...In WindowsXp's cmd,I use "echo %classpath%" ,it returns:
"D:\Program Files\Java\jdk1.5.0_11\bin;D:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;D:\Program Files\Java\jdk1.5.0_11\jre\lib\rt.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.5common\lib"...


If you're going to have a system classpath, it should probably include a dot (.) for the current directory.
 
george zhao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That does really help me lot.
Thanks a million , both of you.
"." means current folder, does it?

And
if JDK's version is below 1.5, pls "java -classpath . Hello"
[ July 18, 2007: Message edited by: george zhao ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by george zhao:
... "." means current folder, does it? ...


Yes. Without that, the JVM would look for the class in each of the paths listed in the classpath, and when it can't find it, it would throw a NoClassDefFoundError. See How classes are found in the Java documentation.

Both -cp and -classpath were java options in 1.4. The documentation omits -cp as a javac option (specifying only -classpath), but as I recall, -cp did work.
[ July 19, 2007: Message edited by: marc weber ]
 
The only cure for that is hours of television radiation. And this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic