Porting to Android: why do I get "Can't create XMLReader by default, is this a system property of org.xml.sax.driver set?"?

I am porting some Java code that worked perfectly on my Android desktop. I have the following code segment:

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
// ...
XMLReader p = XMLReaderFactory.createXMLReader();

On the last line, I get the following exception:

Can't create default XMLReader; is system property org.xml.sax.driver set?

When I tested the code on the desktop, it worked fine. Why am I getting this exception on Android and how to fix it? thank!

+3
source share
3 answers

Android. , factory , , .

:

XMLReader p = XMLReaderFactory.createXMLReader();

:

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser newSAXParser = saxParserFactory.newSAXParser();
XMLReader p = newSAXParser.getXMLReader();

, :)

+9

My solution included the following code in my MainActivity:

System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
+2
source