title: How to make a class with nested objects Parcelable
body: <p>I'd like to make class A Parcelable.</p>
  
  <pre><code>public class A {
      public String str;
      public ArrayList&lt;B&gt; list;
  }
  </code></pre>
  
  <p>This is what I've come up with so far. However it crashes with a NullPointerException. The problem are these two statements: <code>dest.writeList(list);</code> &amp; <code>in.readList(list, this.getClass().getClassLoader());</code>.
  I can't figure out what to do from here :(</p>
  
  <p><strong>Class A</strong></p>
  
  <pre><code>public class A implements Parcelable {
      public String str;
      public ArrayList&lt;B&gt; list;
  
      @Override
      public int describeContents() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(str);
          dest.writeList(list);
      }
  
      private A(Parcel in) {
          str = in.readString();
          in.readList(list, this.getClass().getClassLoader());
      }
  
      public static final Parcelable.Creator&lt;A&gt; CREATOR
              = new Parcelable.Creator&lt;A&gt;() {
          public A createFromParcel(Parcel in) {
              return new A(in);
          }
  
          public A[] newArray(int size) {
              return new A[size];
          }
      };
  }
  </code></pre>
  
  <p><strong>Class B</strong></p>
  
  <pre><code>public class B implements Parcelable {
      public String str;
  
      @Override
      public int describeContents() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(str);
      }
  
      private B(Parcel in) {
          str = in.readString();
      }
  
      public static final Parcelable.Creator&lt;B&gt; CREATOR
              = new Parcelable.Creator&lt;B&gt;() {
          public B createFromParcel(Parcel in) {
              return new B(in);
          }
  
          public B[] newArray(int size) {
              return new B[size];
          }
      };
  }
  </code></pre>
  
  <p>Thank you for your time.</p>