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

Stephen Wall
PLUS
Stephen Wall
Courses Plus Student 27,294 Points

Hangman: won't run, even after copy/paste instructor code...

I am using eclipse to enter my code and even after copy and pasting your code I get the following:

You have 7 tries left to solve: -------- Exception in thread "main" java.lang.NullPointerException at Prompter.promptForGuess(Prompter.java:29) at prompter.play(Prompter.java:13) at Hangmain.main(Hangman.java:10)

In one of the exercises I did between the hangman videos, i ran into a problem using console to print to the screen and take in from the user. I switched a section of code to use the Scanner method instead and it worked. Is this something I should do here too? Or is the problem exclusively with eclipse? I am running on brand new macbook pro retina. OS X El Capitan. I just want this game to work! haha. what am I doing wrong? /Users/stevewall/Documents/Screen Shots/HangmanError.png

Brecht Philips
Brecht Philips
8,863 Points

Can you set a screenshot from your code where the error is here?

Stephen Wall
Stephen Wall
Courses Plus Student 27,294 Points

I can't figure out how to put a screen shot on here....ugggg

2 Answers

Hi Stephen,

The most likely cause of this is the lack of a Console. There's a way of including a console object when starting the project; I don't know what that is. My workaround has always been to do as you suggest and switch to using a Scanner instance.

Good luck!

Steve.

Stephen Wall
PLUS
Stephen Wall
Courses Plus Student 27,294 Points

The Scanner object totally works! So if you are having this same problem, import Scanner, "import java.util.Scanner;" then change your console object to a scanner object, "Scanner input = new Scanner(System.in); " Then just do a simple println to prompt the user to enter a letter, and then set the variable string = to the input variable (or whatever you decide to call it). Mine was " String guessAsString = input.nextLine(); " That change has got me up and running and ready to build on my hangman game! Thanks for the help Steve Hunter!

No problem! :+1: