aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Will compile, but will not run??

Steven Pierce
Greenhorn

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();
p.add(i);
}
}

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
Sheriff

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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Closing this thread. Please continue in the duplicate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Will compile, but will not run??