File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help with First Java Code - Party.Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with First Java Code - Party.Java" Watch "Help with First Java Code - Party.Java" New topic
Author

Help with First Java Code - Party.Java

David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
I am trying to run the very first java app from the book Head First Java. I can get the app to compile. but when I try and run the app I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: party <wrong name: Party/class

Several lines of errors then the last line is..

Could not find the main class: party. Program will exit.

I attached a screen shot of the full error and here is the code that I am trying to compile and run.

Thanks for helping a newbie get started!





[Thumbnail for First Java Error.gif]

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11402
    
  16

Java is case sensitive. "Party" is NOT the same thing as "party".

try "java Party"


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

java party != java Party
David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
One step forward. Ran java Party and now getting this error.




[Thumbnail for First Java Error 2.gif]

David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
Found this simple Java code and was able to compile and run it. Seems like Java is working, but still unable to run the Party application in the quick dip section of Head First Java.







[Thumbnail for First Java Error 3.gif]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So... is there a "main" method in Party?
David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
Not that I can see, but since I only have of a couple of hours of experience with Java I could be wrong.

David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
Added a Main Sub and the code compiles and does not throw an error when ran, but also does not display anything. FYI, this is the entire code base.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

David Wismer wrote:Added a Main Sub and the code compiles and does not throw an error when ran, but also does not display anything. FYI, this is the entire code base.


Which is to be expected... your code creates a frame, a panel, a label, and a couple of buttons. It then add the label to the frame and exits. It doesn't use the panel or buttons, nor displays the frame.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
How would I edit this code so the Main sub does display the panel?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

show()?
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8829
    
    5
Hi David,

Let me fall on my sword This has come up a couple of times before, but it turns out we never intended for you to try to run the code listed on page 3. It was just a sample, not real working code. In our defense, we do have a note at the bottom of the page that says that, but several people have missed that note - our bad.

If you can just hang on for a few more pages you'll get to run a create and run a real program on page 9, and from then on there will be lots of code to write.

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
David Wismer
Greenhorn

Joined: Dec 19, 2009
Posts: 11
Funny! actually glad to have had this little exercise. Anytime you get a chance to problem solve you learn. Time to turn the page.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Maybe you should read the Java tutorial, it's a good read for people without any Java experience. It's also a good read for people with a lot of Java experience


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kelvin scorpio
Greenhorn

Joined: Feb 04, 2011
Posts: 1
Hey guys I seems to be having a different error here. I installed JDK and set my path on the bin directory. After I write the Party.java code, exactly the same as on the head first book, I compiled it and this message shown.

Error: Class names, 'Party' , are only accepted if annotation processing is explicitly requested
1 error


Any idea on how to fix this problem?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Welcome to the Ranch

You write
javac Party.java
java Party
. . . and then it fails because the Party class as given in the Head First book is not a complete application; it is not intended to be run at all. It says at the bottom left of page 3 it is not meant to be a tutorial, and we'll be writing real code later. It might have been a good idea to say the Party class as given there won't run; lots of people get confused about that. And lots of people get the error you have quoted, myself included, all the time, when I forget to write ".java".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with First Java Code - Party.Java