In which line do you get the NullPointerException? The stack trace tells you exactly where the exception happens.
I'm guessing it is in line 32:
When you have "<description/>", that tag does not have any child tags, so el.getFirstChild() returns null. When you try to call a method (getNodeValue() in this case) on a reference that is null, you get a NullPointerException.
Put the result of el.getFirstChild() in a variable, and check if it is null before calling getNodeValue() on it.
Well, those things aren't "under" that "key" at all. At least not in the normal sense where you think of an XML document as a tree structure -- they are in the next branch of the tree. So it's best not to ask the question that way, even if in that text representation of the XML they do appear to be "under" the <key> element.
If you're writing code which navigates through that document via a tree structure (like a DOM for example), and you're looking at a <key> element, then go up to its parent, find the <value> element which is its child, and then find its child which will be a text node.
Joined: Mar 21, 2010
I have tried:
But I can only print out "key duration". The next sibiling value: is null.