Simple Java Help Needed

  • Thread starter Thread starter Deleted member 78630
  • Start date Start date
D

Deleted member 78630

Guest
Hi guys.

I've been having trouble getting THIS simple Java program to work.

It all fails when I try to run the "java HelloWorld" command.

This is the error that I get:

C:\My Work>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.


The "java -version" command works fine, which leads me to believe that my Java Path and ClassPath is correct in Environment Variables???

Any suggestions?

Edit:

I solved the problem by adding -cp to the command so that it looks like this:

java -cp . HelloWorld
 
Last edited by a moderator:
Yes. The java VM didn't know where your class was located, using -cp . gave it the current directory as the classpath.
 
Top
Sign up to the MyBroadband newsletter
X