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

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: 76462
366
  • 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: 76462
366
  • 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.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic