Compiled successfully, but can't use java.exe
Hi all,
I could compile Hello.java with javac successfully, and the Hello.class was created. But when I run with java, it gave me an error :(
For example:
javac Hello.java
>>compiled successfully, Hello.class was created
java Hello
>> gave me an error:
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
I'm sure the code was correct, because I could run it in BlueJ and JCreator. I just can't run it in command prompt. The .class was compiled in command prompt. So, why wouldn't java.exe work in the command prompt?
Thanks
[622 byte] By [
Jetta2006a] at [2007-10-2 12:02:26]

This is what I did with javap
E:\Java Projects\project2>javap Hello
Compiled from "Hello.java"
public class Hello extends java.lang.Object{
public Hello();
public static void main(java.lang.String[]);
}
So, code was correct, javac compiled it successfully, .class was okay too. But why can't I run it with java.exe! It's driving me mad....
The earlier post is correct - the problem is the classpath.
Change to the directory that contains Hello.java and verify that it exists and is correctly named. Then use this command:
java -classpath . Hello
IMPORTANT: include the period and the surrounding spaces.
Learn about finding classes and setting the classpath here:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/index.html#general
Hey ChuckBing,
Thank you!! That solved it.
Could you tell me what this . mean? On *nix system running bash, usually ./ refers to the current directory, but on the command prompt, I tried java -classpath .\Hello and java -classpath ./Hello, both didn't work. Only java -classpath . Hello worked.
What does this . refer to?
Thanks