title: using google maps route drawing app crashes
body: <p>when I start onActivityResult I get Intent and my markers are on the google map, but route between markers is not drawn and after second or two my program crashes. My code and log:</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(requestCode == 1) {
              if(resultCode == RESULT_OK) {
                  Bundle extras = data.getExtras();
                  String result = extras.getString("linija");
                  setMarkers(result);
              }
              if(resultCode == RESULT_CANCELED) {
                  finish();
              }
          }
      }
  
  private void setMarkers(String linija) {
      map.clear();
      try {       
          ruta = SAXXMLParser.parse(getAssets().open("linije/linija" +linija+ ".xml"));
          markerPoints.clear();   
          for (int i = 0; i &lt; ruta.size(); i++) {
              final LatLng lokacija = new LatLng(Double.parseDouble(ruta.get(
                      i).getLat()), Double.parseDouble(ruta.get(i).getLng()));    
              map.addMarker(new MarkerOptions()
                      .position(lokacija)
                      .title(ruta.get(i).getName())
                      .snippet(ruta.get(i).getAddress())
                      .icon(BitmapDescriptorFactory.fromResource(R.drawable.busstop1)));
              markerPoints.add(lokacija);
          }
          if(markerPoints.size() == ruta.size()) 
           {
               for(int j = 1; j &lt; markerPoints.size(); j++) {
                       int i = j - 1;
                       LatLng origin = markerPoints.get(i);
                       LatLng dest = markerPoints.get(j);
                      // Getting URL to the Google Directions API
                      String url = getDirectionsUrl(origin, dest);
                      DownloadTask downloadTask = new DownloadTask();
                          // Start downloading json data from Google Directions API
                      downloadTask.execute(url);
                   }                      
               }                   
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  public String getDirectionsUrl(LatLng origin,LatLng dest){
  
      // Origin of route
      String str_origin = "origin="+origin.latitude+","+origin.longitude;
      // Destination of route
      String str_dest = "destination="+dest.latitude+","+dest.longitude; 
      // Sensor enabled
      String sensor = "sensor=false";
  
      // Waypoints
      String waypoints = "";
      for(int i=2;i&lt;markerPoints.size();i++){
          LatLng point  = (LatLng) markerPoints.get(i);
          if(i==2)
              waypoints = "waypoints=";
          waypoints += point.latitude + "," + point.longitude + "|";
      }
  
      // Building the parameters to the web service
      String parameters = str_origin+"&amp;"+str_dest+"&amp;"+sensor+"&amp;"+waypoints; 
      // Output format
      String output = "json";
      // Building the url to the web service
      String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;
  
      return url;
  }
  
  private String downloadUrl(String strUrl) throws IOException{
      String data = "";
      InputStream iStream = null;
      HttpURLConnection urlConnection = null;
      try{
              URL url = new URL(strUrl);
              // Creating an http connection to communicate with url 
              urlConnection = (HttpURLConnection) url.openConnection();
              // Connecting to url 
              urlConnection.connect();
              // Reading data from url 
              iStream = urlConnection.getInputStream();
              BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
              StringBuffer sb  = new StringBuffer();
              String line = "";
              while( ( line = br.readLine())  != null){
                      sb.append(line);
              }
  
              data = sb.toString();
  
              br.close();
  
      }catch(Exception e){
              Log.d("Exception while downloading url", e.toString());
      }finally{
              iStream.close();
              urlConnection.disconnect();
      }
      return data;
   }
  
  // Fetches data from url passed
  public class DownloadTask extends AsyncTask&lt;String, Void, String&gt;{          
  
      // Downloading data in non-ui thread
      @Override
      protected String doInBackground(String... url) {
  
          // For storing data from web service
          String data = "";
  
          try{
              // Fetching the data from web service
              data = downloadUrl(url[0]);
          }catch(Exception e){
              Log.d("Background Task",e.toString());
          }
          return data;        
      }
  
      // Executes in UI thread, after the execution of
      // doInBackground()
      @Override
      protected void onPostExecute(String result) {           
          super.onPostExecute(result);            
  
          ParserTask parserTask = new ParserTask();
  
          // Invokes the thread for parsing the JSON data
          parserTask.execute(result);
  
      }       
  }
  
  /** A class to parse the Google Places in JSON format */
  private class ParserTask extends AsyncTask&lt;String, Integer, List&lt;List&lt;HashMap&lt;String,String&gt;&gt;&gt; &gt;{
  
      // Parsing the data in non-ui thread        
      @Override
      protected List&lt;List&lt;HashMap&lt;String, String&gt;&gt;&gt; doInBackground(String... jsonData) {
  
          JSONObject jObject; 
          List&lt;List&lt;HashMap&lt;String, String&gt;&gt;&gt; routes = null;                     
  
          try{
              jObject = new JSONObject(jsonData[0]);
              DirectionsJSONParser parser = new DirectionsJSONParser();
  
              // Starts parsing data
              routes = parser.parse(jObject);    
          }catch(Exception e){
              e.printStackTrace();
          }
          return routes;
      }
  
      // Executes in UI thread, after the parsing process
      @Override
      protected void onPostExecute(List&lt;List&lt;HashMap&lt;String, String&gt;&gt;&gt; result) {
  
          ArrayList&lt;LatLng&gt; points = null;
          PolylineOptions lineOptions = null;
  
          // Traversing through all the routes
          for(int i=0;i&lt;result.size();i++){
              points = new ArrayList&lt;LatLng&gt;();
              lineOptions = new PolylineOptions();
  
              // Fetching i-th route
              List&lt;HashMap&lt;String, String&gt;&gt; path = result.get(i);
  
              // Fetching all the points in i-th route
              for(int j=0;j&lt;path.size();j++){
                  HashMap&lt;String,String&gt; point = path.get(j);                 
  
                  double lat = Double.parseDouble(point.get("lat"));
                  double lng = Double.parseDouble(point.get("lng"));
                  LatLng position = new LatLng(lat, lng); 
  
                  points.add(position);                       
              }
  
              // Adding all the points in the route to LineOptions
              lineOptions.addAll(points);
              lineOptions.width(2);
              lineOptions.color(Color.BLUE);              
          }
  
          // Drawing polyline in the Google Map for the i-th route
          map.addPolyline(lineOptions);                           
      }           
  }
  </code></pre>
  
  <p>I just copy/paste what I think is important, so maybe one bracket is missing, there are no errors in eclipse...
  LOGCAT:</p>
  
  <pre><code>08-28 22:03:57.451: E/AndroidRuntime(5248): FATAL EXCEPTION: main
  08-28 22:03:57.451: E/AndroidRuntime(5248): java.lang.NullPointerException
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at ova.&lt;init&gt;(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at oux.b(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at oux.a(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at oyf.a(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at grl.onTransact(SourceFile:137)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at     
  android.os.Binder.transact(Binder.java:297)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at  
  com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.addPolyline(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  com.google.android.gms.maps.GoogleMap.addPolyline(Unknown Source)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at   
  com.project.busme.MainActivity$ParserTask.onPostExecute(MainActivity.java:342)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  com.project.busme.MainActivity$ParserTask.onPostExecute(MainActivity.java:1)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  android.os.AsyncTask.finish(AsyncTask.java:602)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at  
  android.os.AsyncTask.access$600(AsyncTask.java:156)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at  
  android.os.Handler.dispatchMessage(Handler.java:99)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  android.os.Looper.loop(Looper.java:137)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  android.app.ActivityThread.main(ActivityThread.java:4424)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  java.lang.reflect.Method.invokeNative(Native Method)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at  
  java.lang.reflect.Method.invoke(Method.java:511)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at   
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at  
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
  08-28 22:03:57.451: E/AndroidRuntime(5248):     at 
  dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Thanks in advance!</p>