title: Android: Send ArrayList of custom objects from fragment to activity using Parcerable
body: <p>I have a problem making this to work:</p>
  
  <p>1) I have custom class that implements Parcelable:</p>
  
  <pre><code>public class CityCoordinates implements Parcelable {
  
  private double latitude;
  private double longitude;
  
  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;
  }
  
  public CityCoordinates(double latitude, double longitude) {
      this.latitude = latitude;
      this.longitude = longitude;
  }
  
  public CityCoordinates(Parcel in) {
      latitude = in.readDouble();
      longitude = in.readDouble();
  }
  
  public int describeContents() {
      return 0;
  }
  
  public void writeToParcel(Parcel dest, int flags) {
      dest.writeDouble(latitude);
      dest.writeDouble(longitude);
  }
  
  public static final Parcelable.Creator&lt;CityCoordinates&gt; CREATOR = new Parcelable.Creator&lt;CityCoordinates&gt;() {
  
      public CityCoordinates createFromParcel(Parcel in) {
          return new CityCoordinates(in);
      }
  
      public CityCoordinates[] newArray(int size) {
          return new CityCoordinates[size];
      }
  
  };
  </code></pre>
  
  <p>}</p>
  
  <p>2) I have a fragment with ArrayList listItems that I want to send to another activity:</p>
  
  <pre><code>ArrayList&lt;CityCoordinates&gt; listItems = new ArrayList&lt;&gt;();
  ...
  Intent intent = new Intent(getActivity(), MapActivity.class);
              intent.putParcelableArrayListExtra("key", listItems);
              startActivity(intent);
  </code></pre>
  
  <p>3) This is how I retrieve ParcelableArrayListExtra in the activity I started:</p>
  
  <pre><code>public class MapActivity extends ActionBarActivity {
  ...
  ArrayList&lt;CityCoordinates&gt; cityCoordinatesList = getIntent().getParcelableArrayListExtra("key");
  </code></pre>
  
  <p>But I get NullPointerException when I try to retrieve extra. What I am doing wrong? Thank you for your help!</p>