| Author |
Exception in thread "main" java.lang.NullPointerException
|
Garrett Nickel
Greenhorn
Joined: Jul 08, 2009
Posts: 4
|
|
The code compiles just fine, but when I try to run the Launcher, it gives me the message:
Exception in thread "main" java.lang.NullPointerException
at HundredGame.startGame(HundredGame.java:19)
at GameLaunch.main(HundredGame.java:79)
my code is:
Please help, I'm very new to java
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
p1 - p4 are declared, but never initialized. Therefore they are null, and the code fails with a NullPointerException. You must initialize all variables before you use them, i.e.:
p1 = new Player();
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16681
|
|
The stacktrace gives the full details. On line 19 of the HundredGame.java file, in the startGame() method is code, which when called gives a null pointer exception. A null pointer exception is generally thrown when you are trying to dereference (ie. use) an object which hasn't been instantiated.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Garrett Nickel
Greenhorn
Joined: Jul 08, 2009
Posts: 4
|
|
|
Thanks, it works now.
|
 |
 |
|
|
subject: Exception in thread "main" java.lang.NullPointerException
|
|
|