开发者

couldn't Open assets/sample.xml

开发者 https://www.devze.com 2023-02-07 14:29 出处:网络
I m getting the error \"couldn\'t Open assets/sample.xml\" here is my code: try { // creates and returns new instance开发者_运维技巧 of SAX-implementation:

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

精彩评论

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