Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2007, 10:38 AM
Member
 
Join Date: Mar 2007
Posts: 41
peiceonly is on a distinguished road
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 ?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-03-2007, 12:41 PM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
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
Code:
String f = null ; System.out.println("this will cause null pointer exception "+ f.length());
to avoid that always use a null checking
Code:
String f = null ; if(f!==null) System.out.println("this will cause null pointer exception "+ f.length());
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-06-2007, 03:41 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Null pointer exception error brownie_jedi New To Java 3 03-15-2008 07:27 AM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 07:41 PM
What is NULL bugger New To Java 1 01-09-2008 05:55 PM
parameters=null mary Java Servlet 1 07-13-2007 05:29 PM
statement null pointer exception bbq Database 1 07-05-2007 05:23 AM


All times are GMT +3. The time now is 03:09 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org