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

前端 未结 3 1580
半阙折子戏
半阙折子戏 2021-01-13 06:19

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.         


        
相关标签:
3条回答
  • 2021-01-13 06:47

    My solution was including the following code in my MainActivity:

    System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
    
    0 讨论(0)
  • 2021-01-13 06:48

    Resolved by following Parsing an XML File Using SAX (The Java™ Tutorials > Java API for XML Processing (JAXP) > Simple API for XML)

    0 讨论(0)
  • 2021-01-13 06:50

    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 :)

    0 讨论(0)
提交回复
热议问题