Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Exception in thread "main" java.lang.NoClassDefFoundError

 
Ranch Hand
Posts: 633
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
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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: 633
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 VI Editor Java
  • 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.
 
Marshal
Posts: 69894
278
  • 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.
 
Danger, 10,000 volts, very electic .... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic