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 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,309 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