• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Exception in thread "main"  RSS feed

 
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?
 
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!