开发者

couldn't Open assets/sample.xml

I m getting the error "couldn't Open assets/sample.xml"

here is my code:

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

        } 


Assets are not files. You need to call Context.getAssets().open("sample.xml") and pass the resulting InputStream into parse().


Try calling parser.parse("file:///android_asset/sample.xml", handler);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜