File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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: 14074
    
  16

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
Serialization/Deserialization a picture
problems creating a new larger array with one extra element
problem with JTextField null
NullPointerException with setting up an array of Rectangles
Serialization/Deserialization of an Array of Objects