• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Head First Guessing Game Problem

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,

Having trouble getting the "Guessing Game" example from HF Java chapter 2 going.

The "GuessGame" class doesn't compile. Seems it can't find the "Player" class, even tho that compiled without a problem.

Here's the error I get:



The "game" is made of a few classes / files. The point is to generate a random number and to have an automatically created (non-human) "player" guess the number.

The "GuessGame" class




The "Player" class:


The Game Launcher class:


That's it! Seems simple. But I'm not sure what's causing the error. Can I get a "nudge" in the right direction?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Dunphy wrote:The "GuessGame" class doesn't compile. Seems it can't find the "Player" class, even tho that compiled without a problem.


Because it doesn't "need" anything else in order to work.

Have a look at this tutorial page and see if it helps.

Winston
 
Marshal
Posts: 74025
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you copy the code by hand or download it?
If you downloaded the code, it will have a package name, which you don't need at this stage and may cause you confusion. Go to the very top of the file and change
package chapter 03;
to
// package chapter03;
save the files and try again.
 
Tim Dunphy
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Did you copy the code by hand or download it?
If you downloaded the code, it will have a package name, which you don't need at this stage and may cause you confusion. Go to the very top of the file and change
package chapter 03;
to
// package chapter03;
save the files and try again.



Yup! Commenting out that package line was what does the trick! Turning:


To:


allows the game to compile:



And now, thankfully, the game runs!



Thanks for the help!



 
Campbell Ritchie
Marshal
Posts: 74025
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome

You won't believe this, but we have all seen the same problem before.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic