This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main"" Watch "Exception in thread "main"" New topic
Author

Exception in thread "main"

Tom Smith
Greenhorn

Joined: Sep 21, 2005
Posts: 2
I'm learning Java using the Head First Java book. The first code sample provided (just an example, not a tutorial, they say) isn't working.

The .java file compiles without error but I get an error when I execute the program. Here are the details...

Party.java:

import java.awt.*;
import java.awt.event.*;

class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Time's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} // More code here...
}

The commands I use to compile Party.java and execute Party.class are:

> javac Party.java
> java Party
(I've also tried the full file name, Party.class)

The following error is thrown when I execute "java Party":

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

Here are the Java-related environment variables:

CLASSPATH="C:\WINNT\system32\QTJava.zip"
QTJAVA="C:\WINNT\system32\QTJava.zip"
PATH=%PATH%;"C:\Program Files\Java\jdk1.5.0_04\bin"

What am I doing wrong?
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Originally posted by Tom Smith:
I'm learning Java using the Head First Java book. The first code sample provided (just an example, not a tutorial, they say) isn't working.

The .java file compiles without error but I get an error when I execute the program. Here are the details...

Party.java:

import java.awt.*;
import java.awt.event.*;

class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Time's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} // More code here...
}

The commands I use to compile Party.java and execute Party.class are:

> javac Party.java
> java Party
(I've also tried the full file name, Party.class)

The following error is thrown when I execute "java Party":

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

Here are the Java-related environment variables:

CLASSPATH="C:\WINNT\system32\QTJava.zip"
QTJAVA="C:\WINNT\system32\QTJava.zip"
PATH=%PATH%;"C:\Program Files\Java\jdk1.5.0_04\bin"

What am I doing wrong?


You should get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main

bec you didnt added main method.

You will get NoClassDefFoundError when your class is not in classpath.
Tom Smith
Greenhorn

Joined: Sep 21, 2005
Posts: 2
Thanks KJ!

I added the current directory, ".", to my CLASSPATH var and that resolved the NoClassDefFoundError. Afterwards, the error your predicted (NoSuchMethodError) occured.

I guess this particular code example wasn't meant to be used but rather was just illustrating... something.

Thanks again for your reply.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception in thread "main"