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 trialKevin Nguyen
259 Pointsjava.util.NoSuchElementException
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;
}
}
7 Answers
Juan Mendiola
20,751 PointsHey guys,
I got the same error as well, but solved the issue. I compiled Gama.java to see if any errors would show up. One error did. I think due to editing Craig didn't include a return statement in the applyGuess() method, which got me the error. I corrected this in my code and I can now construct a game object.
Kevin Nguyen
259 PointsI was following the video and then I got that. That is the error it gave me
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsOkay, It's returning that it didn't find anything at the index of 0 in your answer I think. In your Hangman.java Class do you have a code that sets the answer? I believe it should look like Game game = new Game("treehouse"); Was that value passed in? Might be the problem.
Kevin Nguyen
259 PointsYes I added that in my code in Hangman.java
Kevin Nguyen
259 PointsNevermind, it just decided to work today but I didn't change anything about the code.
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsThat's very odd, it could have been a lot of things. Glad to hear it worked out.
Kristina Wahlquist
4,519 PointsI am also having the same problem. Below is the code that was included in my Hangman.java file. Wondering if this is a bug with the workspace?
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
}
}
Jorge Flores
7,864 PointsI was getting the same problem, in my case i tried to compile it and found out a syntax error on my code, after i fixed it i was able to create the object with the java-repl i recommend to check the code and look for errors, i dont think there is a bug on the workspace, good luck :3
Leon Mathis
23,404 PointsJust an fyi. I was getting the same error message. Even re-watched the videos to make sure I didn't miss anything. After all attempts, I just restarted my computer and it worked.
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHello, I'm a bit confused were you following along in a video and it Gave you the exception. Or was it a certain code challenfe.? Did the error give a line code?