Honeycomb文档解析错误

时间:2011-12-03 01:33:49

标签: android parsing android-3.0-honeycomb

我已经对这个问题进行了广泛的搜索,尝试了很多修复,但我无法工作......

我正在尝试从我的服务器解析xml文件,我可以检索该文件,但是当我去解析它时,它会出错。这是我的代码:

    public final static Document parse(String xml){
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
            // ERRORS HERE
        is.setCharacterStream(new StringReader(xml));
            //
        doc = db.parse(is);  
    } catch (ParserConfigurationException e) {
        System.out.println("XML parse error: " + e.getMessage());
        return null;
    } catch (SAXException e) {
        System.out.println("Wrong XML file structure: " + e.getMessage());
        return null;
    } catch (IOException e) {
        System.out.println("I/O exeption: " + e.getMessage());
        return null;
    }     
    return doc;
}

这是我得到的错误:

12-02 20:26:22.340: E/AndroidRuntime(11600): java.lang.NullPointerException
12-02 20:26:22.340: E/AndroidRuntime(11600):    at java.io.StringReader.<init>(StringReader.java:48)
12-02 20:26:22.340: E/AndroidRuntime(11600):    at com.arayray.bootanimationutility.tablet.functions.DownloadFunctions.parse(DownloadFunctions.java:41)

1 个答案:

答案 0 :(得分:0)

你确定xml不是空的吗?

这似乎是错误所说的。