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) Delivering the MVP Validation

Tyler Combs
Tyler Combs
15,525 Points

Not sure if this is a bug, but I can't interact with the application after compiling and running.

I'm fairly certain my code is exactly like Craig's in the video. I'm not getting any compiler errors or anything. After entering clear && javac Hangman.java && java Hangman, the console goes blank and when I enter things, nothing happens. I have to use ctrl+c to exit. I know it compiles and runs successfully because I get those little stamps that appear after compiling and executing completes. What's happening?

Edit: Here's a snapshot of my workspace if needed. https://w.trhou.se/nsh4014tlb

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Ohh and it's just the tiniest little thing too. In Prompter.java your while loop has an extraneous semi-colon:

  public void play() {
    while (mGame.getRemainingTries() > 0); {
      // --------------------------------^
      displayProgress();
      promptForGuess();
    }

Using a semi-colon there creates a empty block for the while loop, and since the empty block does nothing it creates an infinite loop. It is technically valid syntax because a single expression and a curly-brace block are equivalent and nothing prevents an empty expression. But it is still an error because the loop does nothing forever.

Tyler Combs
Tyler Combs
15,525 Points

Thanks so much for the help! Seems like my biggest problem so far is learning the syntax. Would it be safe to assume that every time this happens, I managed to create an infinite loop? Or does this also happen because of other things?