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

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -