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) 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.