• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Exception in thread "main" Please help.

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what I'm doing wrong, but I keep getting this error when trying to run my program from source as in java GameLauncher.java:

Exception in thread "main" java.lang.NoClassDefFoundError: GuessGame
at GameLauncher.main(GameLauncher.java:4)

Here is the code for GameLauncher.java:



And from GuessGame.java:



And just in case from Player.java:




This is from the book Head First Java 2nd Edition. The book suggests(?) I use: jave GameLauncher.java to run it. Compiling gives me errors about an unresolved symbol on the three lines with guessp# = p#.number; reffering to the . just before number... Any ideas?

[ February 27, 2005: Message edited by: Michael Baca ]
[ February 27, 2005: Message edited by: Michael Baca ]
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the listing you have for the Player class, number is a local variable in guess() - it doesn't have any field called 'number', so p1.number isn't valid.



With a public field (not good practice) number, things might work better.


[ February 27, 2005: Message edited by: Horatio Westock ]
 
Michael Baca
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well it compiled that time, and it sort of works. The number guessed even if correct does not end the game. But either way it's not a big deal. I guess the author made a mistake in the code. I sure hope the rest of the code in this book works..

Thanks for the help. Btw, what exactly would be 'good practice' in a case such as this one? I thought just making a class public made it accessible to any other class in my program.
[ February 27, 2005: Message edited by: Michael Baca ]
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd probably have the field private, and have accessor methods:



This way, only the object itself can modify it's state. If later, you want to do something special with the field, you can maintain the same accessor methods, so other classes which use it don't have to be changed.
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic