当尝试使用XMLPullParser时,该XmlPullParser.END_DOCUMENT
事件永远不会被调用,因此假设在 while 循环之后执行的代码永远不会被执行。我怎样才能防止这种情况发生?
代码片段:
int eventType = xpp.getEventType();
if(eventType == XmlPullParser.END_DOCUMENT) {
Log.i("app", "End");
return farmers.getFarmers();
}
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
} else if(eventType == XmlPullParser.START_TAG) {
// Do something
} else if(eventType == XmlPullParser.END_TAG) {
// Do something
} else if(eventType == XmlPullParser.TEXT) {
// Do something
}
eventType = xpp.next();
}
if(eventType == XmlPullParser.END_DOCUMENT) {
Log.i("app", "End");
return farmers.getFarmers();
}
return "Some data";
为什么从不调用 return ?