porting to Android: why am I getting "Can't create default XMLReader; is system property org.xml.sax.driver set?"?
Asked Answered
C

3

10

I am porting some Java code that worked fine on my desktop to Android. 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();

At the last line I get the following exception:

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

When I was testing the code on desktop, it was working fine. Why am I getting this exception on Android and how can I fix it? Thx!

Consanguinity answered 15/4, 2012 at 19:50 Comment(0)
B
12

My solution was including the following code in my MainActivity:

System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
Burgin answered 7/7, 2015 at 15:57 Comment(0)
O
10

I just ran into the same issue while porting some code to Android. I found that creating my own factory and parser seems to work.

I'd try replacing this:

XMLReader p = XMLReaderFactory.createXMLReader();

With this:

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

Hope this helps :)

Ohmage answered 5/12, 2013 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.