tags:

views:

17

answers:

1

Hi all, i have parsed xml using dom parser,but when the xml element contains no value it throws null pointer Exception.how to check this?... here my code

NodeList TrackName1 = fstElmnt2.getElementsByTagName("Artist_Name");    


                    Element TrackElement1 = (Element) TrackName1.item(0);

                    TrackName1 = TrackElement1.getChildNodes();
                     result=result+((Node) TrackName1.item(0)).getNodeValue()

                     String  Artistname=((Node)TrackName1.item(0)).getNodeValue();



                                            }
A: 

Just check for null before you try to use the value?

Object value = ((Node) TrackName1.item(0)).getNodeValue();
if (value != null) {
   result = result + value;
}
Mayra