读取本地 XML - 未找到源

发布于 2025-01-05 09:07:21 字数 632 浏览 1 评论 0原文

我正在尝试读取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妥活 2025-01-12 09:07:22

将 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));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文