jQuery in Action, 2nd edition*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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.
 
jQuery in Action, 2nd edition
 
subject: Exception in thread "main"