Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main"

 
Tom Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic