Porting to Android: why do I get “unable to create the default xmlreader; is it the system attribute org.xml.sax.driver setting?”?

I'm porting some java code that works well on my desktop to Android. I have the following code snippet:

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 test the code on the desktop, it works normally. Why do I encounter this exception on Android and how can I solve it? thank you!

resolvent:

I had the same problem porting some code to Android. I found that creating my own factory and parser seemed to work

I tried to replace this:

XMLReader p = XMLReaderFactory.createXMLReader();

With this:

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

I hope this helps:)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>