Sunday 15 February 2015

nullreferenceexception - Null Reference Exception despite checking for Null -



nullreferenceexception - Null Reference Exception despite checking for Null -

i'm reading xml file c# has dynamically generated number of nodes named col1, col2, etc. when effort run while loop on these nodes , check null still nullreferenceexception. can suggest on how handle avoid exception?

int col = 1; string colcount = col.tostring(); colcount = "col" + colcount; while (nodes[0][colcount].innertext != null) { timetofillvalues.add(double.parse(nodes[0][colcount].innertext)); col++; colcount = "col" + col.tostring(); }

since mentioned in comments error happens when checking condition, there few cases should getting error:

if(nodes == null) { // nodes not populated? populate } if(nodes[0][colcount] == null) { // element exist or null? }

check these conditions before calling while loop , should find out wha tis causing issue.

nullreferenceexception

No comments:

Post a Comment