null pointer exception using SAX XML Parser

I am using the SAX Parser for XML Parsing. The problem is if I print, everything is fine. However, If I want to save anything, I get this error message (with the typos):

"XML Pasing Excpetion = java.lang.NullPointerException" 

My code is given below:

Parser code:

try {
        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL(

        /** Create handler to handle XML Tags ( extends DefaultHandler ) */
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler((ContentHandler) myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));

    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);

Object to hold XML parsed Info:

public class ParserObject {

String name=null;
String description=null;
String bitly=null; //single
String productLink=null;//single
String productPrice=null;//single
Vector<String> price=null;

Handler class:

static ParserObject[] xmlDataObject = null;

public void endElement(String uri, String localName, String qName)
throws SAXException {

    currentElement = false;

    if (qName.equalsIgnoreCase("title"))

    else if (qName.equalsIgnoreCase("artist"))


public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {

    currentElement = true;

    if (qName.equalsIgnoreCase("allinfo"))

    else if (qName.equalsIgnoreCase("tags"))


public void characters(char[] ch, int start, int length)
throws SAXException {

    if (currentElement) {
        currentValue = new String(ch, start, length);
        currentElement = false;



Your ParserObject array i.e xmlDataObject is having null value thats is why it is showing null pointer exception. This is my View and it might be wrong but once check it too.

Leave a Reply

Your email address will not be published. Required fields are marked *