This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NoClassDefFoundError

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everybody, I have problem in setting path.

I had installed java in c: drive.
I had set a path lilke this C:\Program Files\Java\jdk1.6.0_05\bin;.;
The program compiles fine but at run time it throw exception as NoClassDeffFoundError.

Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Thanks in advance
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you run the java command from the path of the class file ? is it inside package.
I suggest to compile and run a program from sun's site as described in it and then work on your class.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply,
actually if I set path as

java -classpath . Test

then the programme run succcessfully, but if I set only path as
java Test
it throws Exception.

why is it so?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pramod,
First things first.. PATH and CLASSPATH are different and you got to mention it as CLASSPATH , when you mean CLASSPATH.Secondly when you use -classpath option , it means you are overiding your CLASSPATH value sent in your environment.

So , in the first case it worked because your class lies in the present working directory (pwd) and your -classpath option says "." , which means look for classes only pwd.

In next case , you have not specified so it uses the CLASSPATH value defined in the environment. But your CLASSPATH should either have complete path where Test.class lies or the "." in order for it to find the class. So make sure you add "." to your CLASSPATH variable as well.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set up the system classpath yourself, it is easier to delete the system classpath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic