Problem with the Toast Challenge


#1

I am having a problem with a Toast challenge. I am parsing the xml and getting the total number of returned results. After that, when I’m trying to get that total value, it returns me NULL result. Here are my snippets:

FlickrFetcher:

String totalResults;
.
.
.
public void parseItems(ArrayList<GalleryItem> items, XmlPullParser parser) throws XmlPullParserException, IOException {

        int eventType = parser.next();
        while(eventType != XmlPullParser.END_DOCUMENT) {
            if(eventType == XmlPullParser.START_TAG && XML_PHOTOS.equals(parser.getName())) {
                totalResults = parser.getAttributeValue(null, "total");
            }

            if(eventType == XmlPullParser.START_TAG && XML_PHOTO.equals(parser.getName())) {
                    String id = parser.getAttributeValue(null, "id");
                    String caption = parser.getAttributeValue(null, "title");
                    String smallUrl = parser.getAttributeValue(null, EXTRA_SMALL_URL);
                    String owner = parser.getAttributeValue(null, "owner");

                    GalleryItem item = new GalleryItem();
                    item.setmId(id);
                    item.setmUrl(smallUrl);
                    item.setmCaption(caption);
                    item.setmOwner(owner);

                    items.add(item);
            }

            eventType = parser.next();
        }
    }

    //Returns the result as a string
    public String getTotalResults() {
        return totalResults;
    }

PhotoGalleryFragment:

 @Override
        protected void onPostExecute(ArrayList<GalleryItem> galleryItems) {

                if (mItems == null) {
                    mItems = galleryItems;
                    String total = new FlickrFetcher().getTotalResults();
                    Toast.makeText(getActivity(), total, Toast.LENGTH_LONG).show();
                } else {
                    mItems.addAll(galleryItems);
                }


            setupAdapter();
            mGridView.setSelection(gridScrollPosition);
            fetchedPage++;


        }
    }

I would be really thankful, if somebody could help me.

Thank you very much!


#2
String total = new FlickrFetcher().getTotalResults();

The problem is the total you toasted is belong to a new FlickFetcher instance, not the one you fetch the items.