Java problem: Could not find main class HelloWorld

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-06-09T11:41:54Z Indexed on 2010/06/09 11:52 UTC
Read the original article Hit count: 330

Filed under:

I am new to java(a real novice).

I installed Java 1.7.0 in the following folder C:\Program Files\Java

The environment variable which I set are

CLASSPATH : C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar;

Path : C:\Program Files\Java\jdk1.7.0\bin;

JAVA_HOME : C:\Program Files\Java;

I have presented here the class names which are in my system.

Next I wrote a program(HelloWorld.java)

import java.io.*;

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

When I am compiling using javac HelloWorld.java it is compiling fine.

But after I issue java HelloWorld I am encountering the below error

Error: Could not find main class HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:198)

Caused by: java.lang.ClassNotFoundException: HelloWorld
        at java.net.URLClassLoader$1.run(URLClassLoader.java:299)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:288)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:287)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:422)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:355)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:195)

After a bit of google search I found that may be something wrong in the environment variable. I tried to play with that but no luck.

I know that it may be a very simple thing for the real java developers(actually basic) but for me as of now no luck!

I even RESTARTED the machine and then again I tried to run but with same fate.

OS: Windows XP(Version 2002) with Service pack 3

Help needed .

Thanks .

© Stack Overflow or respective owner

Related posts about java