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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointer Exception error." Watch "NullPointer Exception error." New topic
Author

NullPointer Exception error.

WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
I have an NPE error which starts at line 66, in the setImage() method. I will try my best to reduce as my code shown as possible.

File is GameFrame.java.

Basically, initialize() method calls setImage() method and subsequently, initialize() method is in the GameFrame constructor which is called by the GameFrame main method to be run.

Any help in solving the NPE error is appreciated.









Error code:
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

A NullPointerException almost always happens because you're calling a method on a variable that is null.

In your code, it's most likely puzpiece that is null when line 66 executes. Find out why it is null there, and either add a check or fix the problem so that it's not null when line 66 is reached.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
Jesper de Jong wrote:A NullPointerException almost always happens because you're calling a method on a variable that is null.

In your code, it's most likely puzpiece that is null when line 66 executes. Find out why it is null there, and either add a check or fix the problem so that it's not null when line 66 is reached.


Yup, I solved the issue regarding the NPE.

But now I have a new error - java.lang.IllegalArgumentException: Width (0) and height (0) must be non-zero.

Does this mean that the image import via failed somehow?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointer Exception error.
 
Similar Threads
NullPointerException with setting up an array of Rectangles
problem with JTextField null
Serialization/Deserialization a picture
problems creating a new larger array with one extra element
Serialization/Deserialization of an Array of Objects