XmlResourceParser stays at the START_DOCUMENT state after calling next()

106 Views Asked by At

The following code throws an exception at the 4th line

XmlResourceParser parser = context.getResources().getXml(R.xml.file);
parser.require(XmlPullParser.START_DOCUMENT, null, null);
parser.next();
parser.require(XmlPullParser.START_TAG, null, null);

and after adding debug print statements it turns out that the parser is still in the START_DOCUMENT state after the first call to next(). Adding another call to next() fixes the issue. Such behaviour is wrong per the official Android reference as it says:

START_DOCUMENT

Signalize that parser is at the very beginning of the document and nothing was read yet. This event type can only be observed by calling getEvent() before the first call to next(), nextToken, or nextTag()).

0

There are 0 best solutions below