File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError

 
abheeshek reddy
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i am using java 1.6.0 version.
The path has been set to my C:\Program Files\Java\jdk1.6.0_31\bin directory.

Problem:

i am getting NoClassDefFoundError for all my java programs which i kept in one of my practice folders
Even though my code is correct still i am below error.


E:\Technical\Practice>java SingletonDemo
Exception in thread "main" java.lang.NoClassDefFoundError: SingletonD
Caused by: java.lang.ClassNotFoundException: SingletonDemo
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: SingletonDemo. Program will exit.


below is my java program


please advice me to get out of this problem.


Thanks
abheeshek
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Please check if the .class file is present in the classpath
2. Hope you first compiled using javac before executing java command.
 
abheeshek reddy
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:1. Please check if the .class file is present in the classpath
2. Hope you first compiled using javac before executing java command.




Thanks John for prompt response,
Usual practice is we won't set individual .class files in classpath. However, previously i used to set only path variable in system variables. if required i used set rt.jar file in class path.


thanks


 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abheeshek reddy wrote:
John Jai wrote:1. Please check if the .class file is present in the classpath
2. Hope you first compiled using javac before executing java command.




Thanks John for prompt response,
Usual practice is we won't set individual .class files in classpath. However, previously i used to set only path variable in system variables. if required i used set rt.jar file in class path.


thanks



You don't need to set individual .class files in classpath. Only setting parent directory of package structure would suffice.

I hope this helps.
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant the classpath when the java command is executed.

For sample if you do java SingletonDemo from E:\Technical\Practice, the .class file should be inside the folder (given current folder is the default classpath).

So better try with java -cp . SingletonDemo from the directory that holds the class files.
 
Ravi Vanamala
Greenhorn
Posts: 16
Eclipse IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Along with the PATH, try setting the JAVA_HOME=C:\Program Files\Java\jdk1.6.0_31 in environment "System Variables"
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abheeshek reddy wrote:The path has been set to my C:\Program Files\Java\jdk1.6.0_31\bin directory.

What the PATH is set to, is irrelevant for this question.

Ravi Vanamala wrote:Along with the PATH, try setting the JAVA_HOME=C:\Program Files\Java\jdk1.6.0_31 in environment "System Variables"

That's not going to solve anything either - the Java compiler and launcher do not use the JAVA_HOME environment variable at all.

NoClassDefFoundError means that your CLASSPATH is not correct, so that Java can't find a class it's looking for.

First, compile your source file with the command: javac SingletonDemo.java

If that succeeds without errors, check that you have a file named SingletonDemo.class in the current directory.

Then run it. Use the -cp option to specify the classpath; make sure the current directory "." is in the classpath:

java -cp . SingletonDemo
 
abheeshek reddy
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
abheeshek reddy wrote:The path has been set to my C:\Program Files\Java\jdk1.6.0_31\bin directory.

What the PATH is set to, is irrelevant for this question.

Ravi Vanamala wrote:Along with the PATH, try setting the JAVA_HOME=C:\Program Files\Java\jdk1.6.0_31 in environment "System Variables"

That's not going to solve anything either - the Java compiler and launcher do not use the JAVA_HOME environment variable at all.

NoClassDefFoundError means that your CLASSPATH is not correct, so that Java can't find a class it's looking for.

First, compile your source file with the command: javac SingletonDemo.java

If that succeeds without errors, check that you have a file named SingletonDemo.class in the current directory.

Then run it. Use the -cp option to specify the classpath; make sure the current directory "." is in the classpath:

java -cp . SingletonDemo



Thanks all it worked ... i resolved the problem by setting the current directory in classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic