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

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -