蜂窝文档解析错误
我已经广泛搜索了这个问题,尝试了很多修复,但我无法得到任何工作。
我正在尝试从我的服务器解析一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定 xml 不为空吗?
这似乎就是错误所说的。
And you are sure xml is not null?
That appears to be what the error is saying.