android - Parsing XML results in SAXParseException with Unexpected End of Document -
i running strange error trying parse xml android device. strange parsing xml worked several days before , have not touched code. today, loading xml not work.
the xml files located in "assets" folder in project directory.
here part passing path of specific xml file parser called mazefilereader
.
private void generatefromfile() { log.v(tag, "generating file"); file maze_file = new file(getcachedir() + "/" + pregen_maze); if (!maze_file.exists()) try { inputstream = getassets().open(pregen_maze); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); fileoutputstream fos = new fileoutputstream(maze_file); fos.write(buffer); fos.close(); } catch (exception e) { throw new runtimeexception(e); } mazefilereader mazefilereader = new mazefilereader(getapplicationcontext(), maze_file.getpath());
here mazefilereader
taking path , trying parse it.
private void load(string filename) { try{ file fxmlfile = new file(filename); documentbuilderfactory dbfactory = documentbuilderfactory.newinstance(); documentbuilder dbuilder = dbfactory.newdocumentbuilder(); document doc = dbuilder.parse(fxmlfile); //fails here doc.getdocumentelement().normalize(); nodelist nlist = doc.getelementsbytagname("maze"); (int temp = 0 ; temp < nlist.getlength() ; temp++) { ... } } catch (exception e) { e.printstacktrace();
i've traced error , seems in line of code executes in documentbuilderimpl
if (parser.nexttoken() == xmlpullparser.end_document) { throw new saxparseexception("unexpected end of document", null); }
also, don't think there wrong xml file either have not touched , working several days before. have 4 or 5 other xml files have worked, today, run same saxparseexception
reason. possible reasons saxparseexception
? possible filepath xml incorrect?
here xml in question:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <maze> <sizex> 4 </sizex> <sizey> 4 </sizey> <roomnum> 0 </roomnum> <partiters> 60 </partiters> <cell_0> 173 </cell_0> <cell_1> 132 </cell_1> <cell_2> 140 </cell_2> <cell_3> 198 </cell_3> </maze>
edit: found weird. checked out old version of project , still not work. made new emulator , reinstalled app. works!!! reason behind this?
i've discovered else. xml file run saxparserexception
if debug , step through parsing. file unable parse on. however, if not debug , reinstall app on new device, xml parses correctly. btw, xml located in assets
folder. why android exhibiting sort of behavior?. xml files somehow getting corrupted?
Comments
Post a Comment