aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NullPointerException" Watch "Exception in thread "main" java.lang.NullPointerException" New topic
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: 1296
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: 18896
    
  40

Exception in thread "main" java.lang.NullPointerException
at HundredGame.startGame(HundredGame.java:19)
at GameLaunch.main(HundredGame.java:79)


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.NullPointerException