jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Will compile, but will not run?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

Will compile, but will not run??

Steven Pierce

Joined: May 27, 2004
Posts: 6
Good Afternoon,

OK.. I am going to try not to be a pest here. I am a newbie, so if I am being a pest I am very sorry...

Anyway.. I am trying to use the book Head First Java and it is giving me errors when I try to run it. It took me a while to get it to compile first. I did see that I was using the wrong case on some of the code that I was doing.. Now I see from other notes why.. Anyway..

import java.awt.*;
import java.awt.event.*;
class Party {
public void buildinvite(){
Frame f = new Frame();
Label i = new Label("Party at tim's");
Button b = new Button("You Bet");
Button c = new Button("shoot me");
Panel p = new Panel();

This works fine.. Now if I try to run it either in Javabeans IDE or with the SDK I get the same basic error of:

java.lang.NoClassDefFoundError: lib/party (wrong name: Party) ** I get this with the SDK also. **

// at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main" // is only with an IDE that I am using..

With the SDK I get this:
C:\>j2sdk1.4.2_04\bin\java.exe party
Exception in thread "main" java.lang.NoClassDefFoundError: party

This is what I was told to do in the book..

What am I missing here.
Greg T Robertson
Ranch Hand

Joined: Nov 18, 2003
Posts: 91
Isn't this the same as your other post? Other post - there is info in the other thread to help you
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
In your posted code, the name of the class is Party, not party. So, if this class defines program (i.e. has a main method), you would run it with the command java Party, but the class in the posted code does not include a main method and so cannot be run as a program.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Closing this thread. Please continue in the duplicate.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Will compile, but will not run??
jQuery in Action, 3rd edition