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
Leen Leenaerts
1,096 PointsHangman game
Hi I was making the Hangman game myself without looking to the videos
I got the error:
Exception in thread "main" java.lang.NullPointerException at Prompter.makeGuess(Prompter.java:13) at Hangman.main(Hangman.java:8)
my code :
public class Hangman {
public static void main(String[] args) {
Prompter prompter = new Prompter();
Game game = new Game("cow");
prompter.makeGuess();
}
}
import java.io.Console;
public class Prompter {
public Prompter(){
}
public void makeGuess() {
Console console = System.console();
String guess = console.readLine("Make a guess!");
}
}
public class Game {
private String mWord;
public Game(String word) {
mWord = word;
}
}
Leen Leenaerts
1,096 PointsIt is : String letterAsString = console.readLine("Make a guess!"); But I don't see the problem there
Seth Kroger
56,416 PointsAre you running it in Workspaces or locally?
3 Answers
Seth Kroger
56,416 PointsEclipse has issues with java.io.Console. You need to use System.in and System.out instead:
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.printf("Make a guess: ");
String guess = bufferedReader.readLine();
Leen Leenaerts
1,096 PointsLocally in Eclipse
Leen Leenaerts
1,096 Pointsthanks a lot I just found it out since here it's working I tried to change it to yours and no errors anymore but it doesnt ask me for an input either ok, maybe its just better to work in workspace but now I just want to have it work in Eclipse too, just because it should be possible :D
Mat Sanders
4,819 PointsMat Sanders
4,819 PointsIt's complaining about line 13 in your prompter class. Something not being set. Something coming up null.