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 Storing Guesses

I still get java.until.NoSuchElementException even after I put return isHit in the correct place. What is wrong?

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; } }

3 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Yasir,

In your Game constructor, you initialize "mhits" instead of "mHits". Simple mistake that's easy to miss. I hope that fixes it for you. If not, let me know.

Ryan Ruscett
Ryan Ruscett
23,307 Points

Hey,

Can you fix your mhits. You have them capitalized wrong.

You return return isHit;

But you have mhits

If you fix that does it still throw the same error?

Thank you both, can't believe I made a silly mistake like that Jon Kussmann Ryan Ruscett