Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorldApp


I am newbie in Java Programming. I had learn a little about java at home and had no problem using javac and java. But when i try to run some java code on my office computer, i had error even i only try to display “Hello World”.  I copy the code , wrote it to “C:\gj\” and compiled.  Here the simple code,

class HelloWorldApp {
public static void main(String[] args) {
System.out.println(“Hello World!”); // Display the string.
}
}

When i use “javac HelloWorldApp.java”, it success. But when i use “java HelloWorldApp”, then error occured like this “Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorldApp”. It because java cannot find your bytecode file, HelloWorldApp.class

The solution that i try to fix this

set path=C:\Program Files\Java\jdk1.6.0_12\bin;%path%
set CLASSPATH=C:\GJ

javac HelloWorldApp.java
java HelloWorldApp

or you can try this without setting classpath if you work at the same current folder

java -cp .  HelloWorldApp

10 Responses

  1. Hello,
    Super post, Need to mark it on Digg
    Thanks

  2. It seems that you are not using any java ide. I would suggsest you to use this Google custom search engine to get more relevant results about java
    http://www.searchjava.org

  3. “set CLASSPATH=C:\GJ”
    >Thanks, that fixed it!

    • @kurtThiel
      wat is it mean “set CLASSPATH=c:\GJ”

      • set path for windows environment to know the location where it can run java class

      • assigning ur current folder to classpath

  4. Hi, good post. I have been thinking about this issue,so thanks for sharing. I will certainly be subscribing to your blog.

  5. Dude kudos to you… was breaking up my mind for this error… thanks a lot re.. its just that we have to include the current file name in classpath.. thnks a ton…

  6. Hi guys,

    My name is Alex and I am from Stirling in the UK. I have in recent past discovered this forum and I like it very much.
    I am a bit shy so I wont talk much about me but maybe when I will get more confortable, you guys will get to know me better!
    My main hobbies are playing chess and watching movies. I also like outdoor activites but the temperature has been very bad for the last weeks or so here in Stirling.

    I was wondering if anyone else here is from the united Kingdom too?

    I am happy to have joined this forum!
    Have a nice day!🙂

    PS: Sorry if this was posted in the wrong section. I could not find the right one!

  7. hi new to the forum just like to say hello🙂

    hughseyp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: