A brief description of Null Pointer Exception?

Can someone please give me a brief description of the Null Pointer Exception?

Thanks-

Comments

  • It's an exception occuring when your pointer has the value of null :-).



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Just kidding. Hard to resist :-)

    Well, NullPointerException means that you try to do something to an object that is not created yet. The pointer is nothing but the name of the object. See it like this - you can name your future son right now. (Let's name him Konrad so he sounds intelligent.) Yet, you can't give Konrad any gifts nor spank his ass for peeing on the carpet. Why? Well, he does't exist for one thing...

    If you go [blue]JButton button;[/blue], you don't have any JButton yet, just a name (what you [b]are going to[/b] call it if/when you get one).
    So, you can't tell the JButton that [blue]button.setText ("");[/blue] because button is, kind of, empty (null is Javanese for empty/not assigned).
    Once you [blue]button = new JButton ();[/blue] you'll be able to tell your JButton what to do and think.



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Thanks, just what I needed :)
  • Great. Don't hesitate if there's an other problem (my guess would be "cannot resolve symbol", but you might have already got cleared of that one...)



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories