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 trialStephen Wall
Courses Plus Student 27,294 PointsHangman: 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
Stephen Wall
Courses Plus Student 27,294 PointsI can't figure out how to put a screen shot on here....ugggg
2 Answers
Steve Hunter
57,712 PointsHi 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
Courses Plus Student 27,294 PointsThe 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!
Steve Hunter
57,712 PointsNo problem!
Brecht Philips
8,863 PointsBrecht Philips
8,863 PointsCan you set a screenshot from your code where the error is here?