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]
# 1
Hi,check out if you have set classpath properly: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.htmlL.P.
lukika at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 2
Hi, Thanks for the reply. I'm sure the path was correct, otherwise it wouldn't be able to compile. It just couldn't run the program. Any idea?
Jetta2006a at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 3

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....

Jetta2006a at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 4

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

ChuckBinga at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 5

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

Jetta2006a at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 6
. stands for the current working directory in both the Windows and the Unix world.
BIJ001a at 2007-7-13 8:19:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...