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 I can compile but can't run Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "I can compile but can Watch "I can compile but can New topic
Author

I can compile but can't run

Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
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

Joined: Feb 26, 2005
Posts: 2036
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

Joined: Oct 21, 2006
Posts: 130
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

Joined: Feb 26, 2005
Posts: 2036
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

Joined: Feb 26, 2005
Posts: 2036
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

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: I can compile but can't run
 
Similar Threads
Hi All, While working with Head first java, I got into a problem, please help me to solve this.....
HFJ 2nd - Problem with SimpleDotCom
Problem with a If statement
import java.io.*; problem
This code of mine is not working, Please help.... i am studying from Head first java