0

My part of code is below see,

NodeList nodes=doc.getElementsByTagName("user");
if(nodes.getLength()==0)
system.exit(1);

Initially, xml dont have user element. But, I got an null pointer exception.

How to solve this... And how do I find the no of nodes even if the nodes doesn't exists initially. It shud return 0 nodes. Thank you

Also I checked this....
NodeList nodes=doc.getElementsByTagName("user"); if(nodes==null) system.exit(1);

Then aldo I got null pointer exception.

0 Answers0