-1

I am developing an app that downloads an XML file, parses it and then displays the information on the screen. I get a NullPointerException Exception error in the following code:

here is the code:

private class DownloadXmlTask extends AsyncTask<String, Void, List<vehicleInfo>> {
    @Override
    protected List<vehicleInfo> doInBackground(String... url) {
        try {
            return getvehicles.processBusTime();
        } catch (IOException e) {
           return null;
        } catch (XmlPullParserException e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(List<vehicleInfo> result) {


            for (int record = 0; record < result.size(); record++) {

            double latitude = result.get(record).latitude;
            double longitude = result.get(record).longitude;

                mMap.addMarker(new MarkerOptions().position(new LatLng(latitude,     longitude)).title("Marker"));

        }

    }
}

it is returns a NullPointerException at the line: for (int record = 0; record < result.size(); record++) {

what could be the issue?

thanks.

Helix
  • 59
  • 1
  • 8

2 Answers2

0

result is null. Are you sure that getvehicles.processBusTime() is returning a list?

weiyin
  • 6,819
  • 4
  • 47
  • 58
-1

I would bet money that result is null.

if null is an acceptable value try something like:

 for (int record = 0; result != null && record < result.size(); record++)
Jacob Brewer
  • 2,574
  • 1
  • 22
  • 25