I’m new to java so I might be missing something obvious. I’m trying to create a simple command-line game in java. I use two classes:
The first handles user inputs, the second runs a math question game.
When I try to run the jar file (the eclipse file runs fine), I get an error – can’t be launched, and the following console print out:
Exception in thread "main" java.lang.NullPointerException
at game.GameHelper.getUserInput(GameHelper.java:12)
at game.MultGame.createGame(MultGame.java:18)
at game.MultGame.main(MultGame.java:12)
Any ideas how to fix this? I’m thinking that the problem is related to using the sysout print thing…but Im not sure. Thanks!
A
NullPointerExceptionindicates that a variable was null when being used with either a.or an array reference like[0].The stack trace tells us it happened “at game.GameHelper.getUserInput(GameHelper.java:12)
“. Your source listing has this line at line 12 in GameHelper.
There is only one
.telling us thatinputLinewasnull. How did that happen? Well, it was assigned in line 11.So.
readLine()returned null. How did that happen? Well, from http://download.oracle.com/javase/1.4.2/docs/api/java/io/BufferedReader.html#readLine()So the end of the stream has been reached. The stream was constructed from System.in, so additional information is needed to tell why that may be.