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 › Using of NullPointerException
Page Index Toggle Pages: 1
Using of NullPointerException (Read 255 times)
Using of NullPointerException
Dec 28th, 2008, 10:05pm
 
  I often face to situations when appears Null Pointer Exeptions. So I used to change sequence of different operations. This is very offensive and sometimes it doesn't pay. I would like to ask to skilled people, is there some methods wich don't include execution of piece of data when it poins to null?
Re: Using of NullPointerException
Reply #1 - Dec 29th, 2008, 12:35pm
 
I am not sure to understand "execution of piece of data", I usually execute code, not data.
NPEs (Null Pointer Exceptions) usually come from sequences like someObj.someMethod() where someObj is null.
Why it is null is another issue: is it because data isn't OK
Because a method returned null when meeting an error

In the later case, sometime this can be addressed by returning an "empty" object (eg. an array of size zero, making loops skipping it). See Null object design pattern question for example.

Otherwise, the only way I know is to test against null before using the object.
Re: Using of NullPointerException
Reply #2 - Dec 29th, 2008, 4:27pm
 
Thank you PhiLho! I'll check it.
Page Index Toggle Pages: 1