问题
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
回答1:
Put the XML in res/raw folder and use db.parse(context.getResources().openRawResource(R.raw.wrist));
来源:https://stackoverflow.com/questions/9269077/reading-local-xml-source-not-found