Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default null pointer exception

    show me sample code in which null pointer exception is fixed with good standards

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

    Default

    null pointer exception is fixed
    Better to never have the NPE than to fix it.
    Java Code:
    if (object == null)
      do something else
    else
      ok to use object

  3. #3
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Smile

    Quote Originally Posted by Norm View Post
    Better to never have the NPE than to fix it.
    Java Code:
    if (object == null)
      do something else
    else
      ok to use object
    thanx for ur answer

  4. #4
    Rooneyz is offline Member
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    25
    Rep Power
    0

    Default

    Another one:

    Java Code:
    try
    {
    //code that might throw a NullPointerException
    }
    catch(NullPointerException ex)
    {
    //code when the NPE occurs
    }

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Rooneyz View Post
    Another one:

    Java Code:
    try
    {
    //code that might throw a NullPointerException
    }
    catch(NullPointerException ex)
    {
    //code when the NPE occurs
    }
    Ya, I think this is the best(most suitable) way to handle NullPointerException.

Similar Threads

  1. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 06:48 PM
  2. getting a null pointer exception
    By Rjava in forum XML
    Replies: 4
    Last Post: 07-16-2008, 05:56 AM
  3. Replies: 2
    Last Post: 05-01-2008, 10:14 AM
  4. Null pointer exception error
    By brownie_jedi in forum New To Java
    Replies: 3
    Last Post: 03-15-2008, 06:27 AM
  5. statement null pointer exception
    By bbq in forum JDBC
    Replies: 1
    Last Post: 07-05-2007, 04:23 AM

Posting Permissions

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