Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need Help with Null Pointer Exception

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by kendraheartt; August 14th, 2012 at 03:09 PM.


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Need Help with Null Pointer Exception

    where are the exception messages? Before I scan your code I need to see the exception messages.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Need Help with Null Pointer Exception

    Where are you initializing theShield in the missile? I don't see it in the constructor.

  5. The Following User Says Thank You to Tjstretch For This Useful Post:

    kendraheartt (July 23rd, 2012)

  6. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need Help with Null Pointer Exception

    theShield is in the instance fields

  7. #6
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: Need Help with Null Pointer Exception

    That defines the variable, but where is the assignment?

  8. The Following User Says Thank You to JJeng For This Useful Post:

    kendraheartt (July 23rd, 2012)

  9. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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

Similar Threads

  1. [SOLVED] Getting a null pointer exception.
    By Ouzi in forum What's Wrong With My Code?
    Replies: 14
    Last Post: May 16th, 2012, 11:25 AM
  2. [B]Null Pointer Exception[/B]-- Please Help!!!
    By entwicklerin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 24th, 2012, 11:24 AM
  3. Null Pointer Exception Help !!
    By AlterEgo1234 in forum Member Introductions
    Replies: 1
    Last Post: March 27th, 2011, 10:07 AM
  4. Null Pointer Exception Help!!
    By puzzledstudent in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2010, 06:46 PM
  5. Null Pointer Exception
    By MysticDeath in forum Exceptions
    Replies: 2
    Last Post: October 24th, 2009, 01:49 PM

Tags for this Thread