Forums Register Login

Why NullPointerException?

+Pie Number of slices to send: Send

Im getting a NullPointerException at "hovedvindu.update_player_health();" and I dont understand why...
Can someone tell me?
+Pie Number of slices to send: Send
Hi Kari,

From your post,


private Main hovedvindu;

public Ticker() {
Main hovedvindu = new Main();
t.start();
}



looks like you have had your "hovedvindu" variable shadowed. What you have instantiated in your constructor is a constructor-local variable named "hovedvindu" and not the private instance variable "hovedvindu". Instead of declaring another "hovedvindu" in your constructor, try using

this.hovedvindu = new Main();

instead of

Main hovedvindu = new Main();



Hope this helps.

Regards,

Lhorenz
+Pie Number of slices to send: Send
Ah thanks alot, that fixed it
Then I learned something new
+Pie Number of slices to send: Send
Passing "this" to a new timer up in the variable declarations makes me uncomfortable. You can get into some nasty problems passing "this" around before the constructor is complete. This example looks safe enough because you don't start the Timer until later, but just to form good habits, why not create the Timer right before you start it?
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 639 times.
Similar Threads
instanceof operator
Kathy/Bert book ch 3 self test q 2
instanceof question
Q about instanceof
instanceof example not compiling
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:53:45.