Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:52:50+00:00 2026-05-25T09:52:50+00:00

I am using the SAX Parser for XML Parsing. The problem is if I

  • 0

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(
        "http://50.19.125.224/Demo/VeryGoodSex_and_the_City_S6E6.xml");

        /** 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"))
    {
        xmlDataObject[index].name=currentValue;
    }

    else if (qName.equalsIgnoreCase("artist"))
    {
        xmlDataObject[index].artist=currentValue;
    } 

}


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


    currentElement = true;

    if (qName.equalsIgnoreCase("allinfo"))
    {
        System.out.println("started");
    }

    else if (qName.equalsIgnoreCase("tags"))
    {
        insideTag=1;
    } 

}

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

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

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:52:50+00:00Added an answer on May 25, 2026 at 9:52 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have student.xml file and am parsing this file using SAX Parser and now
I am parsing XML Document using SAX Parser. I want to know which is
I am using the SAX Parser for XML Parsing. The problem is for the
I have a problem with using the SAX parser to parse a XML file.
hi friends i'm using Sax parser for parsing my xml file which i recieve
I parsing the xml using sax parser in android. My xml structure is as
I have been using a SAX parser for a while now to get data
I am getting this error when parsing an incorrectly-generated XML document: org.xml.sax.SAXParseException: The value
I am using SAX Parser to parse the XML file over the network. While
I am trying to parse XML in Perl using XML::SAX parser . My query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.