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 (Retired) Creating the MVP Prompting for Guesses

Joanna Deirmendjian
Joanna Deirmendjian
674 Points

'String cannot be converted to boolean'

Hey there, sorry for the bother.

I am overlooking either a closing bracket or mistyped something here that I cannot for the life of me find, that is giving me the error message:


./Prompter.java:12: error: incompatible types: String cannot be converted to boolean
String guessAsString = console.readline("Enter a letter: ");
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error


Hangman.java:

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("Whoops that was a miss");
  }
}

}


Prompter.java:

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); } }


If anyone can point it out to me, I would much appreciate it!

2 Answers

Joanna Deirmendjian
Joanna Deirmendjian
674 Points

Thank you Alexander! I really appreciate all your help!