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

Another java.util.NoSuchElementException error! What is wrong with my code? Please help.

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

}

Here is the error in repl:

java> :load Game.java
Loaded source file from Game.java
java> Game game = new Game("treehouse");
java.util.NoSuchElementException

2 Answers

Well, after doing that one ten or twenty times, my brain kind of scans for it on its own. But a great way to find what's wrong when your code won't work and you're scratching your head is to use an IDE (integrated development environment). Among other features, these software pinpoint such syntax errors as you type, so you get to find them before compiling. Works great for spotting all those semi-colon errors, missing-curly-brace errors and typo-in-variable-name errors. In the more advanced Java courses, Treehouse teachers use IntelliJ Idea Community Edition, so I'd recommend picking that one if you want to try: https://www.jetbrains.com/idea/

Got it, thank you!

Check your constructor. You want a semicolon instead of a colon after 'mHits = "" '

Thank you, I see it now! How did you find it? Is there a better way to recheck code other than just scanning with your eyes?