0

Possible Duplicate:
.jar file keeps giving me “ could not find the main class”. Program will exit

Trying to run a basic "hello World" program. I have followed step by step tutorials and i get the same error message each time:

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)
Exception in thread "main" 

Here is the Program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Has anyone had this same issue and know how to resolve it?

Community
  • 1
  • 1
Tom
  • 1
  • 1
  • 1

3 Answers3

0

Is the this is the tutorial you are following: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html ?

If not, try to do that one and see if you get the same result.

Also, try to run your application as follows:

C:\java.exe yourjavaprogram.Main

Or you can google the error and you will probably find the solution faster than you think :)

Carlos Quintanilla
  • 12,937
  • 3
  • 22
  • 25
0

Did you compile the program? In command prompt type javac HelloWorld.java This will make a .class file in the same folder. Now type java HelloWorld should work.

0

Make sure your java file is in a package which lives in a "source folder" in Eclipse parlance. That means the icon should look like an open folder containing an orange-ish square with a plus-shape superimposed on it, and the HelloWorld.java file should have a solid blue J on the document icon. If the folder icon just looks like a regular folder, and/or the java file has an outlined J on it, Eclipse won't even compile that code.

Judge Mental
  • 5,209
  • 17
  • 22