We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to avoid a NullPointerException
Page Index Toggle Pages: 1
how to avoid a NullPointerException? (Read 590 times)
how to avoid a NullPointerException?
Sep 3rd, 2007, 4:15pm
 
hi, i have a little problem with NullPointerExceptionS:

I store a reference of object a as the property refToA of object b. when i call method doSomething of property refToA of object b [b.refToA.doSomething()]i get an NullPointerException if object a doesn't exist. how can i avoid that? can i check if object a exists? in actionscript i.e. i could check if object a exists like this [ if(a.refToA){//exists}] how is this done in java?

Re: how to avoid a NullPointerException?
Reply #1 - Sep 3rd, 2007, 5:30pm
 
if ( b.refToA != null ) { /* not null */ }
Re: how to avoid a NullPointerException?
Reply #2 - Sep 4th, 2007, 7:53am
 
fjen wrote on Sep 3rd, 2007, 5:30pm:
if ( b.refToA != null ) { /* not null */ }


Ahhhh! makes sense. thanks
Page Index Toggle Pages: 1