Java

Aaron Williams
Aaron Williams
1,702 Points

Type mismatch: cannot convert from void to String

I am getting the error on String guessAsString

public boolean promptForGuess() {
        String guessAsString = System.out.println("Enter a letter:   ");
        char guess = guessAsString.charAt(0);
        return mGame.applyGuess(guess);
    }
Ken Alger
Ken Alger
Treehouse Teacher

edited for markup

Please see this post for instructions on posting code to the forum.

4 Answers

Henrik Hansen
Henrik Hansen
23,174 Points
System.out.println("Enter a letter:   ");

This is printing a line, not prompting for a string. That is why it won't return anything, instead of returning a String.

Eric De Wildt
PRO
Eric De Wildt
Pro Student 13,077 Points

You need to get the console to read the input on the line from the user. Your current code just prints out a line on the console. So what do you think you need to put to get the console to read some input?

Eric De Wildt
PRO
Eric De Wildt
Pro Student 13,077 Points

That's because the code you posted is wrong. You should get errors anywhere you run the code you posted because it's not right. Try this:

public boolean promptForGuess() {
        String guessAsString = System.out.readLine("Enter a letter:   ");
        char guess = guessAsString.charAt(0);
        return mGame.applyGuess(guess);
    }
Aaron Williams
Aaron Williams
1,702 Points

Ok sorry I said it wrong....... I am not getting errors with the challenge I am getting errors in the eclipse console.