Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sean Mulligan
1,751 PointsPrompting for guesses - where is the error in this?
Hi there,
Getting the following errors:
Hangman.java:6: error: cannot find symbol
Prompter prompter = new Prompter(game);
^
symbol: class Prompter
location: class Hangman
Hangman.java:6: error: cannot find symbol
Prompter prompter = new Prompter(game);
^
symbol: class Prompter
location: class Hangman
2 errors
I have come to recognise that this compilation error is from a spelling mistake or incorrect caps - but I cannot for the life of me find it...
Little help?
import java.io.Console;
public class Prompter { private Game mGame;
public Prompter(Game game) { mGame = game; }
public boolean promptForGuess() { Console console = System.console(); String guessAsString = console.readLine("Enter a letter:"); char guess = guessAsString.charAt(0); return mGame.applyGuess(guess);
} }
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
boolean isHit = prompter.promptForGuess();
if (isHit) {
System.out.println("We got a hit!");
} else {
System.out.println("Ooops that was a miss!");
}
}
}
1 Answer
Daniel Vigil
26,473 PointsGood evening Sean,
I believe you may be missing the import statement to the Prompter class.
The compiler looked in all of the places where the identifier should be defined, and it couldn't find the definition. There is a good list of common issues which cause this error on Stackoverflow here
Sean Mulligan
1,751 PointsSean Mulligan
1,751 PointsHey Daniel,
Cheers for the reply - found the error. I had created the file Prompter.Java instead of Prompter.java.