File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang. NoClassDefFoundError: HelloWorldApp" Watch "Exception in thread "main" java.lang. NoClassDefFoundError: HelloWorldApp" New topic
Author

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

Dan Christensen
Greenhorn

Joined: Nov 04, 2004
Posts: 3
I learned java on MS J++ at school and I have decided to switch over to Sun Java. However, I am not familiar with the common problems in Sun Java. I am trying to get the HelloWorld applet on Sun's website to work. This is the code:

/**
* The HelloWorldApp class implements an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorldApp{
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}


I go to command prompt and type: cd C:\Java\ to get to my applets, then I type: javac HelloWorldApp.java. It builds successfully, but when I type java HelloWorldApp to test it, I get the following error message:
"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp"

I keep getting this error message

My Java JDK is installed at C:\J2sdk1.4.2
My applets are at C:\Java
My path is: C:\j2sdk1.4.2\bin;

Any ideas? Thanks!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See the error explanation about 2/3 into this page...

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Dan Christensen
Greenhorn

Joined: Nov 04, 2004
Posts: 3
I went to those pages and I continue to get the error. I double checkes my path variable and it was exactly what the website said it should be. I can see the build file when I type dir in command prompt, but it will still not work.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

PATH is not the problem -- it's CLASSPATH. Try the advice in the linked page above:

set CLASSPATH=

Then this should work fine. If it does, then you should modify your machine's configuration a bit so this won't be a problem again: see

http://faq.javaranch.com/view?HowToSetTheClasspath

for lots of information about how to do this.


[Jess in Action][AskingGoodQuestions]
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Dan -

Several observations:

First, you're writing an application, not an applet. They're two entirely different creatures, though both are written in Java.

Second, it looks to me like you don't have your classpath set. Try using the full path instead of just the file name when you run. (I like to build a batch file with this info in it. That way I can rerun without typing, I can copy and modify lines for various applications and JVM versions, etc.)
Try running this way:

C:\J2sdk1.4.2\java C:\Java\HelloWorldApp

Give this a try and let us know the results. I'm gone for the day after this post, but I'll check in tomorrow am.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Ernest, you beat me by two minutes! You must be a fast typist! (Typer?)
Dan Christensen
Greenhorn

Joined: Nov 04, 2004
Posts: 3
Ok, I have it working now. For some reason I though the classpath was the path. Like I said, all this Sun Java terminology and stuff is all new to me.

Thanks!
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Dan,

Try using TextPad too instead of the command prompt to compile and run your programs. It is much easier to use. With TextPad, you just click on Tools, compile Java, and if you have no errors, click on Tools again, and click on Run Java Application. I used to use the command prompt too, but I find that the TextPad is so much better. Just thought I'd let you know.
Happy Java-ing.


) ) ) )
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Note to Windows ME users...

You will probably not be able to edit c:\autoexec.bat using a simple text editor, because it will revert to the old settings when you reboot (even if you edit autoexec.bak as well). Instead, follow the instructions in the Sun link above.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang. NoClassDefFoundError: HelloWorldApp