Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.