Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with First Java Code - Party.Java

 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!


First Java Error.gif
Java Error
[Thumbnail for First Java Error.gif]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case sensitive. "Party" is NOT the same thing as "party".

try "java Party"
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java party != java Party
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One step forward. Ran java Party and now getting this error.

First Java Error 2.gif
Windows command error
[Thumbnail for First Java Error 2.gif]
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




First Java Error 3.gif
One works one does not.
[Thumbnail for First Java Error 3.gif]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... is there a "main" method in Party?
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I edit this code so the Main sub does display the panel?

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show()?
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
kelvin scorpio
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic