SAX parser returns null

386 views Asked by At

I am trying to parse an online XML document but when I run the following code, it returns a NULL Exception in the get() method. I tried debugging further to realise that inputstream maybe returning a null value. Anyone know whats wrong?

public class XMLHelper extends DefaultHandler{

private String URL_MAIN = "https://www.ura.gov.sg/LsmMap/xml/lsm-test.xml";

String TAG = "XMLHelper";
Boolean currTag = false;
String currTagVal = "";

private PostValue post ;

private ArrayList<PostValue> postsList = new ArrayList<PostValue>();


//to read the XML
public void get() {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser mSaxParser = factory.newSAXParser();
        XMLReader mXmlReader = mSaxParser.getXMLReader();

        mXmlReader.setContentHandler(this);

        InputStream mInputStream = new URL(URL_MAIN).openStream();
        mXmlReader.parse(new InputSource(mInputStream));

    } catch (Exception e) {
        Log.e(TAG, "Exception123: " + e.getMessage());

    }
}

}

0

There are 0 answers