File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic
Author

NoClassDefFoundError

ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi to every one I had the java 1.6 version in my mechine


C:\>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

I written the following simple program.

class Test
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

I saved this in the C:\ directory. I am able to compile this successfully but when I want try to run this I am getting the following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: Test



C:\>javac Test.java

C:\>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test

why I am getting this Exception at run time please send me the reply if any one had idea.

Thanks in advance.
Ishmayel.

Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
well it is possible that your classpath variable don't have a . in it


<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

What does your CLASSPATH look like? It most likely does not contain '.' (the current directory), as Ivan suggests. Note that if you do not set the CLASSPATH evironment variable at all, Java will automatically look in the current directory.

Since this question does not really have much to do with the SCJP exam, I am moving this to the Java in General (Beginner) forum. Please continue there.

For more information about CLASSPATH, see: http://faq.javaranch.com/java/HowToSetTheClasspath
[ April 28, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
BABUN GHOSh
Greenhorn

Joined: Apr 03, 2008
Posts: 7
try this

c:\cd "JAVAPRJ"
c:\directory>javac hello.java
c:\directory>java hello

assume that java file stored in a directory named "JAVAPRJ"


Aveek
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi,

I already set the classpath,path and JAVA_HOME but why the simple java program is not running on my mechine. I try to run the simple *.class file
with package and without package but I did not.

Any *.java file is compiling fine but not running.

what is the problem..?

Actually I have Java 1.5 version on my mechine I set every thing in environment variables but that was run some day's with out any problem.
After some time I installed Net Beans IDE 6.0 with that java 1.6 is installed on my mechine...I didn't set any environment variable for java 1.6 but when I try the follwoing command I am getting this ::

C:\>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


If any one had idea help me.
Thanks & regards...
Ishmayel.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3477
    
  13
Try this command
C:\>java -cp . Test

Note the spaces around the .


Joanne
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi..
Thanks for your repply..

I tried that command java -cp . Test
Now my .class file is running on my mechine...
But what is the difference between the following commands.

c:\>java Test
&&

C:\> java -cp . Test

Thanks & Regards,
Ishmayel.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38461
    
  23
The difference is that the -cp . adds the "." to the classpath, which means that "java" looks for whichever class you are executing in the "." as well as the rest of the classpath.

The "." means the directory your command prompt happens to be open in, the current directory.
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi..
why I have to alway run my .class file with java -cp . Test
how can I eliminate this ?
i already set my CLASS PATH, PATH and JAVA_HOME.
can any one have any idea..?
Thanks in advance...
Ishmayel.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38461
    
  23
Plase copy and paste your CLASSPATH environment variable.
And why you are working at the root of your C drive rather than in a "Java" folder? Please use mkdir to create a "java" folder and try working inside that.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3477
    
  13
Originally posted by ishmayel vemuru:
Hi..
why I have to alway run my .class file with java -cp . Test
how can I eliminate this ?
i already set my CLASS PATH, PATH and JAVA_HOME.
can any one have any idea..?
Thanks in advance...
Ishmayel.


When you're just learning and only writing small apps, it is not a problem to use the CLASSPATH environment variable. However, once your apps start getting more complicated and you need to make use of different 3rd party jar files with each app then the CLASSPATH variable will become very difficult to maintain. Using the -cp option will enable you to specify a different classpath for each of your applications. If you don't want to write the whole command line each time, then you can just put it in a btach/script file and run that. Later on you will learn about jar files which will also make it easier.
 
jQuery in Action, 2nd edition
 
subject: NoClassDefFoundError