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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -