• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with First Java Code - Party.Java

 
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for First-Java-Error.gif]
Java Error
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java is case sensitive. "Party" is NOT the same thing as "party".

try "java Party"
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java party != java Party
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One step forward. Ran java Party and now getting this error.

First-Java-Error-2.gif
[Thumbnail for First-Java-Error-2.gif]
Windows command error
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for First-Java-Error-3.gif]
One works one does not.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So... is there a "main" method in Party?
 
David Wismer
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would I edit this code so the Main sub does display the panel?

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
show()?
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic