Results 1 to 5 of 5
  1. #1
    wired-in=p is offline Member
    Join Date
    Jul 2011
    Posts
    38
    Rep Power
    0

    Default NullPointerExecptions

    I keep getting a null pointer exception in a pacman program I'm designing. There is only one object reference in the line that has the error. I know i instantiated that object, too. In addition, the line works, as in it returns the correct number despite having a null pointer exception. The code isn't too long, so I don't know if i should post it or not.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: NullPointerExecptions

    Quote Originally Posted by wired-in=p View Post
    I keep getting a null pointer exception in a pacman program I'm designing. There is only one object reference in the line that has the error. I know i instantiated that object, too. In addition, the line works, as in it returns the correct number despite having a null pointer exception. The code isn't too long, so I don't know if i should post it or not.
    You may think that you've instantiated the variable, but you haven't -- at least not at the point where you're trying to use it. Perhaps a local variable is shadowing a class field? Hard to say without some code.

    Norm and I specialize in variable shadowing. :)

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: NullPointerExecptions

    We need to see the FULL text of the error message and the lines of code that are referenced in the error message.

    You could look at the error message and see where in your program the error occurred and then look at that statement to determine which variable is null. Then backtrack in your code to see why the variable does not have a valid value.

  4. #4
    wired-in=p is offline Member
    Join Date
    Jul 2011
    Posts
    38
    Rep Power
    0

    Default Re: NullPointerExecptions

    I already checked the line and it contains one object reference and i know it isn't null.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: NullPointerExecptions

    Quote Originally Posted by wired-in=p View Post
    I already checked the line and it contains one object reference and i know it isn't null.
    The JVM isn't lying, and something on the line that is throwing the exception is null, regardless of what you or I say. And again, have you checked for variable shadowing? This is something that can make it look like we've initialized a variable when in fact we have not.

    But more importantly you've got two folks asking for the code, the full error message, and an indication of which line throw the NPE. Why continue to debate when we can see for sure? Let's see what you've got. :)
    Last edited by Fubarable; 09-24-2011 at 05:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •