• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

NullPointer Exception error.  RSS feed

 
Ranch Hand
Posts: 94
  • 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:
 
Java Cowboy
Posts: 16084
88
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: 94
  • 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?
 
Whatever. Here's a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!