无法打开assets / sample.xml

时间:2011-01-27 12:16:11

标签: android

我收到错误“无法打开assets / sample.xml

这是我的代码:

try {
            // creates and returns new instance of SAX-implementation:
            SAXParserFactory factory = SAXParserFactory.newInstance();

            // create SAX-parser...
            SAXParser parser = factory.newSAXParser();
            // .. define our handler:
            SaxHandler handler = new SaxHandler();

            // and parse:
            parser.parse("assets/sample.xml", handler);

        } 

2 个答案:

答案 0 :(得分:2)

资产不是文件。您需要调用Context.getAssets().open("sample.xml")并将生成的InputStream传递给parse()

答案 1 :(得分:0)

尝试调用parser.parse(“file:///android_asset/sample.xml”,handler);