读取本地 XML - 未找到源
我正在尝试读取 XML 文件的资源,但收到错误“未找到源”,我将代码粘贴在下面,请告诉我哪里做错了,
public void ParseXmlFile() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse((InputStream) context.getResources().getXml(R.xml.wrist));
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
我将“wrist.xml”放置在 res/xml 文件夹中
I am trying to read a resource of an XML file but I am getting error "Source Not Found", I am pasting my code beneath, please tell me where I am doing wrong
public void ParseXmlFile() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse((InputStream) context.getResources().getXml(R.xml.wrist));
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
I am placed "wrist.xml" in res/xml folder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 XML 放入 res/raw 文件夹中并使用 db.parse(context.getResources().openRawResource(R.raw.wrist));
Put the XML in res/raw folder and use db.parse(context.getResources().openRawResource(R.raw.wrist));