Lists Home |
Date Index |
Here you are testing whether the string value of the first child node of chh
is equal to null. No string in Java ever equals(null) - String.equals(object)
only ever returns true if the object is an instanceof String, and null is not an
If chhh has no children, such as the <description/> element in
your example, there is no first child, and getFirstChild() will return null
. Attempting to call getNodeValue() on that null reference will cause a
NullPointerException to be thrown, which you are observing.
If you are using Java 1.4, use (chhh.getFirstChild() != null) or
(chhh.getChildCount() > 0) before walking down the tree accessing the text
(and remember that if your source document has not been normalised or contains
comments or processing instructions the text content of the element may be
spread across many nodes, and the node value of the first node may not be text
If you are using Java5 then calling getTextContent()  on chhh hides
This email and any files attached are intended for the addressee and may contain information of a confidential nature. If you are not the intended recipient, be aware that this email was sent to you in error and you should not disclose, distribute, print, copy or make other use of this email or its attachments. Such actions, in fact, may be unlawful. In compliance with the various Regulations and Acts, General Dynamics UK Limited reserves the right to monitor (and examine for viruses) all emails and email attachments, both inbound and outbound. Email communications and their attachments may not be secure or error- or virus-free and the company does not accept liability or responsibility for such matters or the consequences thereof. Registered Office: 100 New Bridge Street, London EC4V 6JA. Registered in England and Wales No: 1911653.