Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xml getText return null - Android

i'm using XmlPullParser on Android but get getText return null. Why is this happening?

The code, the commented line gives the null

    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");
    }
like image 937
Clepto Avatar asked Jun 02 '13 08:06

Clepto


1 Answers

Try this:

if (xpp.getName().equalsIgnoreCase(TITLE)) {
  if(xpp.next() == XmlPullParser.TEXT) { 
       MainActivity.itemsList.add(xpp.getText());
       Log.d("XGamers", "a");
  }
}

Also, make sure your itemsList is initialized.

like image 55
Ryhan Avatar answered Nov 01 '22 20:11

Ryhan