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

mMisses += letter error?

I'm at 6:20 on the video and keep getting the following error when trying to compile:

location: class Game ./Game.java:23: error: unexpected type mMisses += letter;

required: class found: value

HERE IS MY CODE:

public boolean applyGuess(char letter)
boolean isHit = mAnswer.indexOf(letter) >= 0; if (isHit) {
mHits += letter;
}else { mMisses += letter; }

2 Answers

What first i see is that you are missing {} around you applyGuess. And as you didn't put the code i will assume you made public game method. and that you declared the variables. But what i know of this fault is that it cannot find the type as it is not declared anywhere.

Declared variables

private String mAnswer;
private String mHits;
private String mMisses;

public Game:

public Game(String answer){
    mAnswer = answer; 
    mHits = "";
    mMisses = "";
  }

if you have the public game method you applyGuess method should work. Full code should look something like this Game.java

public class Game {

private String mAnswer;
private String mHits;
private String mMisses;

public Game(String answer){
    mAnswer = answer; 
    mHits = "";
    mMisses = "";
}

public boolean applyGuess(char letter){
    boolean isHit = mAnswer.indexOf(letter) >= 0;
    if (isHit){
      mHits += letter;
    }else {
      mMisses += letter;
    }
    return isHit;
  }
}

Hope this will help.

Ahh, your right it was literally that 1 { symbol right after
public boolean applyGuess(char letter) { All good now. Thanks for your help.

Your welcome. glad i could help.