title: Passing ArrayList between activities
body: <p>I have an activity where I am adding objects into an ArrayList which implements the Parcelable interface. I then pass this list to another activity via a bundle however I get the following error when I try to print the size of the list in the new activity:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to resume activity {com.example.test/com.example.test.SectionsActivity}: java.lang.NullPointerException</p>
  </blockquote>
  
  <p>Here is the first activity where I add to list:</p>
  
  <pre><code>    @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
      Toast.makeText(getApplicationContext(), l.getItemAtPosition(position).toString() + " added to order", Toast.LENGTH_SHORT).show();
      // add clicked item to orderData....
      MenuItem m = (MenuItem) l.getItemAtPosition(position);
      // create new item
      orderData.add(m);
      subTotal += m.getPrice();
      calc();
  }
  </code></pre>
  
  <p>This is first activity where I send the data via intent:</p>
  
  <pre><code>confirmBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              b.putParcelable("order", orderData);
              Intent i = new Intent(v.getContext(), SectionsActivity.class);
              i.putExtra("data",b);
              startActivity(i);
  
          }
      });
  </code></pre>
  
  <p>and this is second activity where I try to retrieve the bundle and display size:</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
      getIntentData();
  }
  
  
  public void getIntentData(){
      Intent i = getIntent();
      if(i != null &amp; i.hasExtra("data")){
          Toast.makeText(this.getApplicationContext(), "recieved", Toast.LENGTH_LONG).show();
          b = i.getExtras();
          orderData = b.getParcelable("order");
          int size = orderData.size();
          Toast.makeText(this.getApplicationContext(), String.valueOf(size), Toast.LENGTH_LONG).show();
  
      }
  }
  </code></pre>
  
  <p>Any ideas why I am getting the null pointer?? It's driving me mad!</p>
  
  <p>orderData is a MenuItemList object:</p>
  
  <pre><code>public class MenuItemList extends ArrayList &lt;MenuItem&gt; implements Parcelable{
  
  /**
   * 
   */
  private static final long serialVersionUID = 2998684930374219271L;
  
  
  
  public MenuItemList(){
  
  }
  
  public static final Parcelable.Creator&lt;MenuItemList&gt; CREATOR = new Parcelable.Creator&lt;MenuItemList&gt;() {
  
      @Override
      public MenuItemList createFromParcel(Parcel source) {
          return new MenuItemList(source);
      }
  
      @Override
      public MenuItemList[] newArray(int size) {
          return new MenuItemList[size];
      }
  
  
  };
  
  
  public MenuItemList(Parcel source) {
          readFromParcel(source);
  }
  
  private void readFromParcel(Parcel source) {
  
      this.clear();
  
      //read the size of the list
      int size = source.readInt();
  
      //Remember order of items written into the Parcel. Important here.
      for(int i = 0; i &lt; size; i ++){
          MenuItem item = new MenuItem();
          item.setName(source.readString());
          item.setPrice(source.readDouble());
          this.add(item);
      }
  }
  
  @Override
  public void writeToParcel(Parcel dest, int flags) {
      int size = this.size();
  
      dest.writeInt(size);
  
      for(int i = 0; i &lt; size; i ++){
          MenuItem item = this.get(i);
          dest.writeString(item.getName());
          dest.writeDouble(item.getPrice());
  
      }
  
  }
  
  @Override
  public int describeContents() {
      return 0;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>CHANGES TO CODE THAT SOLVED PROBLEM:</p>
  
  <p>CHANGED onClick(View v):</p>
  
  <pre><code>@Override
          public void onClick(View v) {
              Intent i = new Intent(v.getContext(), SectionsActivity.class);
              i.putExtra("data", (ArrayList&lt;MenuItem&gt;)orderData);
              startActivity(i);
  
          }
  </code></pre>
  
  <p>CHANGED getIntent():</p>
  
  <pre><code>public void getIntentData(){
      Intent i = getIntent();
      if(i != null &amp;&amp; i.hasExtra("data")){
          Toast.makeText(this.getApplicationContext(), "recieved", Toast.LENGTH_LONG).show();
          orderData = i.getParcelableExtra("data");
          int size = orderData.size();
          Toast.makeText(this.getApplicationContext(), String.valueOf(size), Toast.LENGTH_LONG).show();
  
      }
  }
  </code></pre>