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
Andrew Park
6,130 PointsHangman.java:14 error: reached end of file while pars ing
I keep getting this message when I try to compile javac.Hangman.
public class Hangman {
public static void main(String[] args) {
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.displayProgress();
boolean isHit = prompter.promptForGuess();
if (isHit) {
System.out.println("We got a hit!");
} else {
System.out.println("Whoops that was a miss");
}
prompter.displayProgress();
I re-checked Craig's code like 5 times but I can't figure out what the problem is.
1 Answer
Derek Markman
16,291 PointsThat specific error occurs when you are missing a closing curly brace '{'. I'm not sure if you posted all of your code, but just by what you posted I can see that you're missing a closing curly brace for your MAIN METHOD and CLASS.
Assuming your other code is correct, this should work:
public class Hangman {
public static void main(String[] args) {
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.displayProgress();
boolean isHit = prompter.promptForGuess();
if(isHit) {
System.out.println("We got a hit!");
} else {
System.out.println("Whoops that was a miss");
}
prompter.displayProgress();
} //this is the closing curly for the main method
} //this is the closing curly for the class
Let me know if you need any other help.
Andrew Park
6,130 PointsI get even more errors when I add the 2 curly braces at the end.
It now says Hangman.java:7: error: cannot find symbol
prompter.displayProgress();
^
symbol: method displayProgress()
location: variable prompter of type Prompter
and says the same thing for the 14th line as well.
Derek Markman
16,291 PointsOk well that means it cant find your "displayProgress()" method inside of your Prompter class. Go to Prompter.java, and go check for your displayProgress() method. Make sure that the spelling of the displayProgress() method is the same as it is in Hangman.java.
If you want you can just paste your full Prompter.java code for me.
Alternatively, you can just download the files that are associated for your specific video lesson, and that should include all of the code that you need to continue with your lesson.
Andrew Park
6,130 PointsThx fixed it :)
markmneimneh
14,133 Pointsmarkmneimneh
14,133 PointsAre you missing a }
?? as in
public static void main(String[] args) {
Game game = new Game("treehouse"); Prompter prompter = new Prompter(game); prompter.displayProgress(); boolean isHit = prompter.promptForGuess(); if (isHit) { System.out.println("We got a hit!"); } else { System.out.println("Whoops that was a miss"); } prompter.displayProgress(); }