Need Help with Null Pointer Exception
Okay so I am writing a program for a space invaders game, and i keep getting a null pointer exception when in my missile class. I can't seem to figure out what went wrong... If anyone could help me out I would really appreciate it :) I've only been taking Java for about a year, so this is probably a really easy problem, but I just need a little bit of help to get me on the right track :) I'm also new to this forum so i don't really know what I'm doing, sorry if I do something wrong :(
the arrow i put in the text is where I keep getting the null pointer exception... The Shield class is below
The Shield Class
okay so basically i am trying to hide the filled rect at the array element that is visible when the missile interesects the shield. i have the basics off it down, but i still keep getting a null pointer exception. this is similar to what it should look like, but if anyone can help me figure out why i am getting that null pointer exception at the highlighted point, i would really appreciate it. in between the big arrows in the Shield class is where the isHit method that is being called is located. Thanks again :)
Re: Need Help with Null Pointer Exception
where are the exception messages? Before I scan your code I need to see the exception messages.
Re: Need Help with Null Pointer Exception
I got this message when I ran the applet:
Exception in thread "Thread-36" java.lang.NullPointerException at Missile.run(Missile.java: 108)
this only happened when I shot the missile, but it the missile was shooting before i added the line that the arrow is pointing to in the missile class, and thats where the exception is, so I'm pretty sure I did something wrong in that line or in the isHit method
Re: Need Help with Null Pointer Exception
Where are you initializing theShield in the missile? I don't see it in the constructor.
Re: Need Help with Null Pointer Exception
theShield is in the instance fields
Re: Need Help with Null Pointer Exception
That defines the variable, but where is the assignment?
Re: Need Help with Null Pointer Exception
Oh okay thats what I did wrong :) I assigned it and it works now thank you so much :)