Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can compile but can't run

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the DotCome game in HFJ. I can compile it but when I try to run it I get the error message
D:\MyFiles>java S1
Exception in thread "main" java.lang.NoClassDefFoundError: S1.

Below is the code

What am I doing wrong? Any help would be welcome
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you put the below on your dos prompt, what do you see?


You may have an issue about classpath. You can view the FAQ #9.

http://faq.javaranch.com/view?JavaRanchFaq
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I get:

D:\MyFiles>set CLASSPATH
CLASSPATH=C:\Program Files\Java\jre1.5.0_10\lib\ext\QTJava.zip
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tontang Bei:
This is what I get:

D:\MyFiles>set CLASSPATH
CLASSPATH=C:\Program Files\Java\jre1.5.0_10\lib\ext\QTJava.zip


You should know that that error you had means, that the class file mentioned cannot be found.

The classpath should include the folder or path where your classes (those files generated when you compiled your source code) are.

The dot character '.' represents the current directory. If the classes are in same folder where you are executing the run, the dot should be in the classpath. For example (Notice the dot after the = sign?):



On how to set the classpath, the FAQ might have it.
[ February 18, 2007: Message edited by: Jesus Angeles ]
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick fix if your situation is:
>>>no package
>>>the classes are in the folder where you executed the 'java' to run the program

Put this in your dos prompt, press enter, and run again

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic