In my xml there can be empty tags like </title>.
The problem is that when I parse the xml, I am getting null pointer exception when I reach this line in the xml.
How should I check tags like this in my parsing file?
ArrayList<String>textcomment = new ArrayList<String>();
for(int i = 0;i<nl.getLength();i++)
{
Element e = (Element)nl.item(i);
// crash on this string find first time a value and second time find </no_of_comments>
String noOfcomment = e.getElementsByTagName("no_of_comments").item(0).getFirstChild ().getNodeValue();
aryNoOfcomment.add(i, noOfcomment);
}
What is the line with problem?
It’s this line?
You are getting everything in the same line, so you don’t check if one of them was null.
You can separate and then check if the result is null, like this: