Thread: NullPointerException

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 NullPointerException 
    Registered Member
    Lingerz's Avatar
    Join Date
    Dec 2008
    Age
    29
    Posts
    396
    Thanks given
    2
    Thanks received
    2
    Rep Power
    176
    Code:
    java.lang.NullPointerException
            at ObjectClicking.objectOption1(ObjectClicking.java:107)
            at client.parseIncomingPackets(client.java:16386)
            at client.packetProcess(client.java:14010)
            at client.packetSending(client.java:13963)
            at PlayerHandler.process(PlayerHandler.java:153)
            at server.main(server.java:50)
    I get that when I try use my ObjectClicking class I created. I've Google'd the NullPointerException and read about it, but I don't quite understand it. Can anyone explain it in more detail?
    Reply With Quote  
     

  2. #2  
    Apple Computers
    Bridget7298's Avatar
    Join Date
    Aug 2007
    Age
    32
    Posts
    1,088
    Thanks given
    99
    Thanks received
    49
    Rep Power
    219
    I'll try to explain this best as I can..

    here's an example:

    Code:
    String w = null ;
    System.out.println("this will cause null pointer exception  "+ w.length());
    That can cause a nullpointer exception so you can avoid it by checking the null first like this:

    Code:
    String w = null ;
    if(w!==null)
    System.out.println("this will cause null pointer exception  "+ w.length());
    Sorry if you dont quite get it.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Lingerz's Avatar
    Join Date
    Dec 2008
    Age
    29
    Posts
    396
    Thanks given
    2
    Thanks received
    2
    Rep Power
    176
    Thanks for trying, but that didn't expand my understanding too much, nor did it make me realize how to prevent it. :/
    Reply With Quote  
     

  4. #4  
    Registered Member
    rmb7's Avatar
    Join Date
    Nov 2008
    Posts
    1,023
    Thanks given
    2
    Thanks received
    12
    Rep Power
    200
    Here I will try.

    if you have String w = null; and you dont asign it anything you will get that exeption because you cant have a nulled string. Its like when you say something but you dont make any noise. People are like huh?

    So to prevent it you do something like if(w != null) { then the rest of your code.

    Then if you want you can put } else { System.out.println("w is a null"); }
    Reply With Quote  
     

  5. #5  
    Donator


    Join Date
    Mar 2008
    Posts
    1,945
    Thanks given
    118
    Thanks received
    201
    Rep Power
    2104
    at ObjectClicking.objectOption1(ObjectClicking.java:1 07)

    show this
    Attached image
    Reply With Quote  
     

  6. #6  
    Registered Member
    Lingerz's Avatar
    Join Date
    Dec 2008
    Age
    29
    Posts
    396
    Thanks given
    2
    Thanks received
    2
    Rep Power
    176
    Quote Originally Posted by lmctruck30 View Post
    at ObjectClicking.objectOption1(ObjectClicking.java:1 07)

    show this
    Code:
    	if (c.absX == 3215 && c.absY == 3476
    	 || c.absX == 3215 && c.absY == 3477) {
    		c.makeGlobalObject(3215, 3477, 1537, -6, 0);
    Lines 106-108.

    Quote Originally Posted by rmb7 View Post
    Here I will try.

    if you have String w = null; and you dont asign it anything you will get that exeption because you cant have a nulled string. Its like when you say something but you dont make any noise. People are like huh?

    So to prevent it you do something like if(w != null) { then the rest of your code.

    Then if you want you can put } else { System.out.println("w is a null"); }
    Hmm... I get it a little better now. Still, I haven't worked out how to stop it from that.
    Reply With Quote  
     

  7. #7  
    Donator


    Join Date
    Mar 2008
    Posts
    1,945
    Thanks given
    118
    Thanks received
    201
    Rep Power
    2104
    c.absX == 3215 && c.absY == 3477

    your making the object spawn onto of a player

    and to the idiot above saying w != null createglobalobject checks for null you idiot

    dont make the object spawn on the player and the try making the orientation or -6 like 0 or -1
    Attached image
    Reply With Quote  
     

  8. #8  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Variable is set to null, then you try to refrance from the null variable, a nullpointerexception will be thrown because the var = nothing.
    Reply With Quote  
     

  9. #9  
    Donator


    Join Date
    Mar 2008
    Posts
    1,945
    Thanks given
    118
    Thanks received
    201
    Rep Power
    2104
    Quote Originally Posted by RogueX View Post
    Variable is set to null, then you try to refrance from the null variable, a nullpointerexception will be thrown because the var = nothing.
    in that case your saying absX or absY is null.... this nullpointer is pointing at absx or Y

    it is never null unless the player is destructed meaning the thread is null....
    Attached image
    Reply With Quote  
     

  10. #10  
    Registered Member
    Lingerz's Avatar
    Join Date
    Dec 2008
    Age
    29
    Posts
    396
    Thanks given
    2
    Thanks received
    2
    Rep Power
    176
    Quote Originally Posted by lmctruck30 View Post
    c.absX == 3215 && c.absY == 3477

    your making the object spawn onto of a player

    and to the idiot above saying w != null createglobalobject creates for null you idiot

    dont make the object spawn on the player and the try making the orientation or -6 like 0 or -1
    It was working before I added it into a separate class file, and the orientation is already -6.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Tags for this Thread

View Tag Cloud

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