title: Android - Displaying Polyline
body: <p>The concept of my application is that a a path is drawn every time a user sets two markers on a map and that path is shown in another activity. I have saved the path (waypoints) as an Array list in my FireBase database and I have also retrieved the way points in the second activity, but I am having problems displaying the poly line in the second activity. My database:</p>
  
  <p><a href="https://i.stack.imgur.com/nFJdM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nFJdM.png" alt="enter image description here"></a></p>
  
  <p>My POJO classes:</p>
  
  <pre><code>public static class Route {
  
      private ArrayList&lt;Location&gt; locations;
  
      public Route() {
      }
  
      @PropertyName("route")
      public ArrayList&lt;Location&gt; getLocations() {
          return locations;
      }
  
      @PropertyName("route")
      public void setLocations(ArrayList&lt;Location&gt; locations) {
          this.locations = locations;
      }
  }
  
  
  public static class Location {
      private Double latitude;
      private Double longitude;
  
      public Location() {
      }
  
      public Double getLatitude() {
          return latitude;
      }
  
      public void setLatitude(Double latitude) {
          this.latitude = latitude;
      }
  
      public Double getLongitude() {
          return longitude;
      }
  
      public void setLongitude(Double longitude) {
          this.longitude = longitude;
      }
  }
  </code></pre>
  
  <p>Retrieval of waypoints:</p>
  
  <pre><code> userRef.child("Route").addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              Route route = dataSnapshot.getValue(Route.class);
              for (Location location : route.getLocations()) {
                  points = new ArrayList();
                  double lat = location.getLatitude();
                  double lng = location.getLongitude();
                  position = new LatLng(lat, lng);
                  points.add(position);
              }
          }
  </code></pre>
  
  <p>To add the polyline to the map I do this:</p>
  
  <pre><code> PolylineOptions lineOptions = null;
      lineOptions.add(position);
      lineOptions.width(12);
      lineOptions.color(Color.RED);
  
      mMap.addPolyline(lineOptions);
  </code></pre>
  
  <p>But I get this exception : </p>
  
  <blockquote>
    <p>"NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.model.PolylineOptions com.google.android.gms.maps.model.PolylineOptions.add(com.google.android.gms.maps.model.LatLng)' on a null object reference"</p>
  </blockquote>