aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread 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 "Exception in thread "main" Please help." Watch "Exception in thread "main" Please help." New topic
Author

Exception in thread "main" Please help.

Michael Baca
Greenhorn

Joined: May 27, 2004
Posts: 17
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

Joined: Feb 23, 2005
Posts: 221
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

Joined: May 27, 2004
Posts: 17
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

Joined: Feb 23, 2005
Posts: 221
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" Please help.