Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dan Christensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the error explanation about 2/3 into this page...

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
 
Dan Christensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest, you beat me by two minutes! You must be a fast typist! (Typer?)
 
Dan Christensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic