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

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,176 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
PLUS
Eric De Wildt
Courses Plus 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
PLUS
Eric De Wildt
Courses Plus 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.