我在Android上使用XmlPullParser,但getText返回null。 這是怎麼回事?Xml getText返回null - Android
的代碼中,註釋行給出了空
ArrayList<String> titleList = new ArrayList<String>();
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(this.getInputStream(), null);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase(TITLE)) {
// MainActivity.itemsList.add(xpp.getText());
Log.d("XGamers", "a");
}
}``
eventType = xpp.next();
}
} catch (XmlPullParserException e) {
Log.e("XGamers", "XmlPullParserException in FeedParser");
} catch (IOException e) {
Log.e("XGamers", "IOException in FeedParser");
}
xpp.getName()是否爲null或者執行該行時是否存在NullPointerException? – Ryan
我將行更改爲getText,之前是錯誤的.. NullPointerException何時執行 – Clepto