蜂窝文档解析错误

发布于 2024-12-19 07:59:15 字数 1295 浏览 3 评论 0原文

我已经广泛搜索了这个问题,尝试了很多修复,但我无法得到任何工作。

我正在尝试从我的服务器解析一个 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)

I've searched far and wide about this issue, tried many fixes but I cannot get any to work..

I'm trying to parse an xml file from my server, I can retrieve the file okay but when I go to parse it, it errors. Here is my code:

    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;
}

and here is the error I'm getting:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2024-12-26 07:59:15

你确定 xml 不为空吗?

这似乎就是错误所说的。

And you are sure xml is not null?

That appears to be what the error is saying.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文