java - XML Parser : How to avoid null pointer exception -
when given key not exist throws npe
.
string nodevalue = eelement.getelementsbytagname(key).item(0).gettextcontent(); if (nodevalue == null || nodevalue.isempty()) return null; return nodevalue;`
try string nodevalue=null; if(eelement!=null && eelement.getelementsbytagname(key)!=null && eelement.getelementsbytagname(key).item(0)!=null ){ nodevalue = eelement.getelementsbytagname(key).item(0).gettextcontent(); } return nodevalue;
Comments
Post a Comment