• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointer Exception error.

 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic