nullpointerexception - What is the best practice to avoid null pointer /un parsable exception when an array returns a null -
let's have
for(object[] ob:bftotobj) { double sal1= double.parsedouble(string.valueof(ob[0])); double sal2= double.parsedouble(string.valueof(ob[1])); double sal2= double.parsedouble(string.valueof(ob[2])); }
if array returns null, leads null pointer exception or number parsing exception that.
one way surround every thing in try, catch.
other way put
for(object[] ob:bftotobj) { if(ob[0]!=null) double sal1= double.parsedouble(string.valueof(ob[0])); if(ob[1]!=null) double sal2= double.parsedouble(string.valueof(ob[1])); if(ob[0]!=null) double sal2= double.parsedouble(string.valueof(ob[2])); }
to values.
is there better way this? or best way it?
Comments
Post a Comment