aspose file tools*
The moose likes XML and Related Technologies and the fly likes null pointer exception to get first child node while xml parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "null pointer exception to get first child node while xml parsing" Watch "null pointer exception to get first child node while xml parsing" New topic
Author

null pointer exception to get first child node while xml parsing

shalu pareek
Greenhorn

Joined: Nov 14, 2008
Posts: 14
Hi ,
i am trying to retrive the first child node and want to put in Map. but its throwing me null pointer exception. How to get only the first child of the xml file.
Below is my code:

if (reqNode != null) {
Node nodeList1 = reqNode.getFirstChild();

if (nodeList1 != null) leftFrstMap.put(nodeList1.getAttributes().getNamedItem("label").getNodeValue(), nodeList1.getAttributes().getNamedItem("href").getNodeValue());
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42623
    
  65
The first step is to ascertain which of the many object used in this code is null. Then you can start investigating why it might be null.


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

Often beginners with DOM assume that the getFirstChild method will return the first child which is an Element, not noticing that there is a Text node which is all whitespace before that Element in their document. This Text node is the first child.

Have a look at your document to see if that is the case.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception to get first child node while xml parsing