Results 1 to 9 of 9
  1. #1
    peiceonly is offline Member
    Join Date
    Mar 2007
    Posts
    41
    Rep Power
    0

    Default Null pointer Exception

    Hi
    Im beginner to java.
    Just to in the stage of copy paste code .
    Frequently seeing the exception Null pointer Exception.
    What does this mean ?

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    This may be the first exception one find in his code , Best coding practices will make this exception disappear from your code.
    This exception simply say ,that used object is null
    Java Code:
    String f = null ;
    System.out.println("this will cause null pointer exception  "+ f.length());
    to avoid that always use a null checking
    Java Code:
    String f = null ;
    if(f!==null)
    System.out.println("this will cause null pointer exception  "+ f.length());

  3. #3
    levent Guest

    Default

    This may be the first exception one find in his code
    Yes, this is one of the first things a Java programmer need to interpret. To understand it fully, you need to learn objects and their references.

    When you see a null pointer exception. You should go to the line specified in the error and check if there might be any null references there. To do that you can add basic "if statements" for your object references used around that line (just like goldhouse did for f variable in the above code.). Once you found the null reference variable, you can fix the problem by changing the code there. This step is application specific: you might need to make sure that no null reference is there or you can allow null references but control the program flow for not getting a null pointer exception.
    Last edited by levent; 04-06-2007 at 03:43 PM.

  4. #4
    g25451 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Default

    hello, how are you?

  5. #5
    mindblaster's Avatar
    mindblaster is offline Member
    Join Date
    Dec 2009
    Location
    Pakistan
    Posts
    18
    Rep Power
    0

    Default

    always avoid to Null Pointer Exception from this method

    try{

    // some code

    }catch(NullPointerException e)
    {
    // code that shows error descroption
    }
    Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

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

    Default

    Quote Originally Posted by mindblaster View Post
    always avoid to Null Pointer Exception from this method

    try{

    // some code

    }catch(NullPointerException e)
    {
    // code that shows error descroption
    }
    No, this is a very bad idea as this will just mask bad program design. Better is to write code that avoids NullPointerExceptions in the first place. With practice you will get better at doing this.

    Edit: also, isn't this thread a bit long in the tooth to be replying to? It's over a year old.
    Last edited by Fubarable; 02-06-2010 at 12:15 AM.

  7. #7
    mindblaster's Avatar
    mindblaster is offline Member
    Join Date
    Dec 2009
    Location
    Pakistan
    Posts
    18
    Rep Power
    0

    Default

    i think when problem is solved or thread is old it should be locked.

    because i never seen the date to thread when posting a reply ;)
    Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

  8. #8
    jason75 is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default having problem w\virtual radio for lg rumor touch

    hi, new , im having a problem with trying to get virtual radio on my lg
    i down loaded to pc jad & jar files then to memory card then to phone it comes on for a sec then i get this message unaccepted exception the application caused an error and will be terminated nullpointer exception
    please help its driving me crazy want to listen to radio on phone
    thanks

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

    Default

    Is this a program that you yourself have written in Java? If so, the error message will tell you which line in the source code is causing the exception. If not, then not much we can do other than to tell you to contact your vendor. This would be way beyond the scope of this forum.

    Edit: well, you never responded, so I assume that it's the latter issue, that you're not a Java developer but rather a consumer in which case you should contact the vendor. If I'm wrong and you are a developer, then please start a new thread for your question. Given the age of this one, I'm locking it.
    Last edited by Fubarable; 09-05-2010 at 08:29 PM.

Similar Threads

  1. Null pointer exception error
    By brownie_jedi in forum New To Java
    Replies: 3
    Last Post: 03-15-2008, 07:27 AM
  2. Replies: 1
    Last Post: 03-08-2008, 07:41 PM
  3. What is NULL
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 05:55 PM
  4. parameters=null
    By mary in forum Java Servlet
    Replies: 1
    Last Post: 07-13-2007, 05:29 PM
  5. statement null pointer exception
    By bbq in forum JDBC
    Replies: 1
    Last Post: 07-05-2007, 05: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
  •