• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my first java program

 
ramesh tadiparthi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you verified that there is a Test.class file after compiling?

Are you changing to the directory that contains that Test.class file?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch! See if this tutorial helps.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
ramesh tadiparthi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic