Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

'Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld'

  Asked By: Kent    Date: Sep 11    Category: Java    Views: 8915

I am a beginner.
When i run a java code, i got a message:

'Exception in thread "main" java.lang.NoClassDefFoundError:

What's wrong? What should I do?



7 Answers Found

Answer #1    Answered By: Dinh Tran     Answered On: Sep 11

try java  -cp "." HelloWorld

the . tells Java to look in the current directory for the file.

Answer #2    Answered By: Ann Evans     Answered On: Sep 11

check . is there in the classpath.
JVM is not able to find ur class to load...

Answer #3    Answered By: Dan Romero     Answered On: Sep 11

if you are using Windows do this
set classpath=%classpath%;.;
type the above command in the command prompt from the directory of your class
file location.
suppose the class file is in c:\java
open command prompt and change directory to java
and issue the command.

if you are unix

Answer #4    Answered By: Clint Garcia     Answered On: Sep 11

I was just trying using my new download programm: NetBeans IDE 3.5.1

with a simple program named Hello

* Hello.java
* Created on January 23, 2004, 11:48 PM

* @author Rulx Narcisse

public class Hello
{ public static void main  (String [] args)
{ System.out.println("Mon premier Programme Java");};

But when trying to execute it I received the same message: Exeption
in thread  "main" java.lang.NoClassDefFoundError:Hello
I have used the command "java Hello".

I have tried too the command java  -cp"." Hello as mentionned, but
received the message  " Unrecognized option:-cp Could not create the
Java Virtual Machine "

Can you help me find the problem?

Answer #5    Answered By: Wilfred Young     Answered On: Sep 11

your class which has the main  method should have exactly the same
name wint your .java file

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

should be saved as HelloWorld.java

Answer #6    Answered By: William Bouchard     Answered On: Sep 11

on the dos prompt enter the following commnd and u will be fine!
>SET PATH = %PATH%;c:\java...(your java.exe file's directory)

recompile the prg and then run  it

Answer #7    Answered By: Vivek Lakshmanan     Answered On: Aug 13

The reason behind this problem is that your class file generated after the compilation of your java file is not present in the folder that is been located by the classpath. So, hence you check it by going in to Advanced system settings in the control panel and click the environment variables in the popped out window. Here you have to add the ClASSPATH field and the loaction of your jdk\bin folder. (in my case C:\Program Files (x86)\Java\jdk1.6.0\bin

If still the problem persists then add a '.' value to the CLASSPATH by using a ';' to differentiate btw two values. (in my case .;C:\Program Files (x86)\Java\jdk1.6.0\bin;)