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) Delivering the MVP Refactoring

it says my message is not simplified enough and my guessAsString is not correct

public boolean promptForGuess() {
    Console console = System.console();
    boolean isHit = false;
    boolean isValidGuess = false;
   while (! isValidGuess) {
    String guessAsString = console.readLine("Enter a letter:  ");

     try {
       isHit = mGame.applyGuess(guessAsString);
     isValidGuess = true;
     } catch (IllegalArgumentException iae) {
      console.printf("%s. Please try again.\n", iae.getMessage()); 
     }

   }
    return isHit;

error message:

public boolean promptForGuess() {
    Console console = System.console();
    boolean isHit = false;
    boolean isValidGuess = false;
   while (! isValidGuess) {
    String guessAsString = console.readLine("Enter a letter:  ");

     try {
       isHit = mGame.applyGuess(guessAsString);
     isValidGuess = true;
     } catch (IllegalArgumentException iae) {
      console.printf("%s. Please try again.\n", iae.getMessage()); 
     }

   }
    return isHit;
Craig Dennis
Craig Dennis
Treehouse Teacher

Oops looks like you posted the code instead of the error message. Can you re-post please

Craig Dennis
Craig Dennis
Treehouse Teacher

Please please please include the error. Also note the timestamp on the comment before this one.

./Prompter.java:25: error: incompatible types: String cannot be converte d to char
isHit = mGame.applyGuess(guessAsString);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

this is my error message. but I'm not sure how to upload a snapshot onto a question?

1 Answer

Allan Clark
Allan Clark
10,810 Points
String guessAsString = console.readLine("Enter a letter:  ");

     try {
       isHit = mGame.applyGuess(guessAsString);

The applyGuess() method only accepts a single char. This is trying to send in a String. You will need to trim down the String to just the first char of the String.

String guessAsChar = guessAsString.charAt(0);

try {
       isHit = mGame.applyGuess(guessAsChar);