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

Java Java Objects Creating the MVP Prompting for Guesses

David Lanipekun
David Lanipekun
564 Points

can't find the problem in my code keep getting the same errors

public class Hangman {

public static void main(String[] args) { // Your incredible code goes 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("Oops missed"); } } }

What are the errors you get? Can you post them here?

David Lanipekun
David Lanipekun
564 Points

./Prompter.java6: error: reached end of file while parsing } ^ Hangman.java:7 error: cannot find symbol Boolean isHit = prompter.promptForGuess();

symbol: method promptForGuess() location: variable prompter of type Prompter. 2 errors

Can you post the code in your Prompter class? It seems something is missing there.

David Lanipekun
David Lanipekun
564 Points

rewrote everything and this is what I got:

Hangman.java:7 error: cannot find symbol Boolean isHit = prompter.promptForGuess(); ^ symbol: method promptForGuess() location: variable prompter of type Prompter. 1 error

David Lanipekun
David Lanipekun
564 Points

This is my rewritten prompter

import java.util.Scanner;

class Prompter { private Game game;

public Prompter(Game game) { this.game = game; }

public boolean promptForGuess() { Scanner scanner = new Scanner(System.in); System.out.print("Enter a letter: "); String guessInput = scanner.nextLine(); char guess = guessInput.charAt(0); return game.applyGuess(guess);

}

}

David Lanipekun
David Lanipekun
564 Points

rewritten hangman

public class Hangman {

public static void main(String[] args) { // Your incredible code goes 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("Oops missed"); } } }

michaelcodes
michaelcodes
5,604 Points

Hi there David! If you are working on this project within the treehouse "Workspaces" you can post a snapshot of your workspace here which will help speed up the process of getting help :)

You can do so by opening up the workspace, then at the top right hand corner you should see 3 icons. The left most icon kind of looks like a camera, if you click that it will let you take a snapshot of your workspace and give you a link that you can post here! Happy coding!

David Lanipekun
David Lanipekun
564 Points

http://w.trhou.se/bkfb9ecneu

this is my error; Hangman.java:7 error: cannot find symbol Boolean isHit = prompter.promptForGuess(); ^ symbol: method promptForGuess() location: variable prompter of type Prompter. 1 error

2 Answers

There is a typo in your Prompter class. It should be promptForGuess with a capital F, not promptforGuess. Java cares about capitalization. For the compiler, you're calling a method that doesn't exist.

David Lanipekun
David Lanipekun
564 Points

Thank you how do I make the method exist? I followed the video.

michaelcodes
michaelcodes
5,604 Points

Hi david, to answer your last question here, the method will exist as long as you type the name correct :)

Livia was just saying that if you don't have the proper capital letters in the name (Matches exactly) the compiler will think your referencing something entirely different, something that doesnt exist!