Reading Local XML - Source Not Found

扶醉桌前 提交于 2019-12-13 04:28:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!