Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes my first java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "my first java program" Watch "my first java program" New topic
Author

my first java program

ramesh tadiparthi
Greenhorn

Joined: May 17, 2006
Posts: 2
i am trying to execute my first java program.
i have compiled successfully.
i tried to execute with the command "java Test"
it gives me the error message as "java.lang.NoClassDefFoundError: Test"

what is the problem and how can i fix this problem.

thanks in advance.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Have you verified that there is a Test.class file after compiling?

Are you changing to the directory that contains that Test.class file?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch! See if this tutorial helps.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Another tutorial that describes your problem (which is, by the way, a very common problem for people writing their first Java application):

Getting Started - The "Hello World" Application

Try searching the forum or Google for "NoClassDefFoundError".


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
ramesh tadiparthi
Greenhorn

Joined: May 17, 2006
Posts: 2
Hi all,

Thanks for the feedback. I checked in the folder where the .java file is there and after compilation the .class file also is in there. But i still get the same error.

In the path variable i have added C:\Program Files\Java\jdk1.5.0_06\bin;
and the CLASSPATH variable is set to C:\Java\jre1.5.0_06\lib\ext\QTJava.zip
.java and .class files are in "jdk1.5.0_06\bin\examples" directory

I am trying to execute in the command prompt from
C:\Program Files\Java\jdk1.5.0_06\bin\examples>
I don't know why I still keep getting this message.
where does the "java" command look for the .class file.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by ramesh tadiparthi:
...the CLASSPATH variable is set to C:\Java\jre1.5.0_06\lib\ext\QTJava.zip
.java and .class files are in "jdk1.5.0_06\bin\examples" directory...

I think that's the problem: If you're starting out, you should usually not set a system CLASSPATH value. If you delete this setting, then Java will revert to its default of looking for classes in the current directory, and you should be okay. But if you must set a CLASSPATH value, then be sure to add a dot (.) to the list so that Java will look in the current directory. If you are on a Windows machine, use a semicolon to separate values. Note the semicolon and dot at the end...

C:\Java\jre1.5.0_06\lib\ext\QTJava.zip;.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my first java program