I am trying to parse xml using JDOM and if the tag value is empty it throws null pointer exception even though i check for null value.
code NodeList description = rootElement.getElementsByTagName("description"); for (int i = 0; i < description.getLength(); i++) { Element el = (Element)description.item(i); if(el.getFirstChild().getNodeValue()!=null||!"".equals(el.getFirstChild().getNodeValue())) {System.out.println("description value"+el.getFirstChild().getNodeValue());} }
You're checking "el.getFirstChild().getNodeValue()" for null, but you're not checking 'el.getFirstChild()" for null. And since "description" has no children, it will be null.
I have also tries if(el.getFirstChild()!=null||!"".equals(el.getFirstChild())) {System.out.println("description value"+el.getNodeValue());} } but it prints description value as null even if description has value.