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 Delivering the MVP Validating and Normalizing User Input

After the implementation in this video, I keep getting a compilation error: prompter.displayProgress(); error!

Hi there, the error message:

"./Prompter.java:43: error: ';' expected
public void displayProgress()
^
./Prompter.java:43: error: illegal start of expression
public void displayProgress()
^
./Prompter.java:43: error: ';' expected
public void displayProgress()
^
Hangman.java:11: error: cannot find symbol
prompter.displayProgress();
^
symbol: method displayProgress()
location: variable prompter of type Prompter"


My code:

//Promter.java (from line 43)

public void displayProgress() { System.out.printf("You have %d tries to solve: %s%n", game.getRemainingTries(), game.getCurrentProgress()); }

//Hangman.java (from line 9)

while (game.getRemainingTries() > 0) { prompter.displayProgress(); prompter.promptForGuess(); }

Snapshot: https://w.trhou.se/fw1dd1lgk8

thank you :)

1 Answer

andren
andren
28,558 Points

You are missing a closing bracket } for the do while loop in the promptForGuess method. Java is complaining because the bracket mismatch is causing it to not consider the class to be closed, which makes it confused when another class suddenly appears in the code.

I see. It's a good experience. As a beginner it seems to me that the problem is directly in the method mentioned in the error message, the displayProgress(), and not anywhere else in the class it belongs to. Hard to deduce. Thank you andren!

andren
andren
28,558 Points

Yeah it can sometimes be a bit challenging to deduce exactly where the true source of an error originates. But in most cases it will either be in the line that is pointed at or slightly above it.

One tip I can give it that one of the error messages you got illegal start of expression is often a good indicator that the error originates in some code above the line that is pointed at. The error is essentially saying that it did not expect this line of code to appear, which is usually caused by things like missing semicolons, brackets or something similar in the code above it.

Perfect! Thank you again.