Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Delivering the MVP Validation

Tyler Combs
Tyler Combs
15,512 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,405 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,512 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?