读取本地XML - 未找到源 [英] Reading Local XML - Source Not Found

查看:112
本文介绍了读取本地XML - 未找到源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取XML文件的资源,但我正在错误找不到源代码,我下我的贴code,请告诉我哪里做错了。

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

我放在wrist.xml在res / XML文件夹

I am placed "wrist.xml" in res/xml folder

推荐答案

把XML在res /原始文件夹,使用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));

这篇关于读取本地XML - 未找到源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆