dcsimg
How to handle Null Pointer exception?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, August 25, 2006 07:06 AM

Hi how to handle/prevent NullPointer Exception?

Re: How to handle Null Pointer exception?

Posted By:   Anonymous  
Posted On:   Friday, August 25, 2006 09:56 AM


Foo foo = bar.couldReturnNull();
if (foo != null)
{
foo.doSomething();
}
else
{
//do Something interesting
}

//OR - To use handle in the Java literal sense of the word
Foo foo = bar.couldReturnNull();
try
{
foo.doSomething();
}
catch (NullPointerException e)
{
System.out.println("bar.couldReturnNull() returned null");
}

Re: How to handle Null Pointer exception?

Posted By:   WarnerJan_Veldhuis  
Posted On:   Friday, August 25, 2006 08:20 AM

Make sure all your objects are initialised before you use them.
About | Sitemap | Contact