I am parsing XML datas, but when in XML is tag without text (only <item/> ) it writes error:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String org.w3c.dom.Node.getNodeValue()' on a null object reference
This is function where I get error:
private static String getNode(String sTag, Element eElement) {
NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
.getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue(); //here I get error
}
Can somebody help me with this problem? Thank you very much.
nullif it is not nullreturnvalue if it isnullreturn something else for example an emptyStringnlList.item(0)existed, doesn't mean it's not null