Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" Please help.

 
Michael Baca
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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 ]
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic