title: NullPointerException when trying to read parcel ArrayList<Object>
body: <p>I've got a class Message that implements Parcelable. It partly contains an ArrayList, AttachmentsData is also one of my classes. When I'm trying to pass a Messageobject from my MainActivity to another activity I get NullPointerException when trying to read this ArrayList.
  AttachmentsData also implements Parcelable.</p>
  
  <p>The error:</p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start
    activity
    ComponentInfo{com.example.incentive/com.example.incentive.Comments}:
    java.lang.NullPointerException 1at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
    android.app.ActivityThread.access$600(ActivityThread.java:127)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
    android.os.Handler.dispatchMessage(Handler.java:99)
    android.os.Looper.loop(Looper.java:137)
    android.app.ActivityThread.main(ActivityThread.java:4441)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:511)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    dalvik.system.NativeStart.main(Native Method) Caused by:
    java.lang.NullPointerException
    android.os.Parcel.readTypedList(Parcel.java:1638)
    com.example.incentive.messagemodel.Message.readFromParcel(Message.java:88)
    com.example.incentive.messagemodel.Message.(Message.java:40)
    com.example.incentive.messagemodel.Message$1.createFromParcel(Message.java:103)
    com.example.incentive.messagemodel.Message$1.createFromParcel(Message.java:1)
    android.os.Parcel.readParcelable(Parcel.java:1992)
    android.os.Parcel.readValue(Parcel.java:1854)
    android.os.Parcel.readMapInternal(Parcel.java:2094)
    android.os.Bundle.unparcel(Bundle.java:223)
    android.os.Bundle.getParcelable(Bundle.java:1158)
    com.example.incentive.Comments.onCreate(Comments.java:70)
    android.app.Activity.performCreate(Activity.java:4465)
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)</p>
  </blockquote>
  
  <p>In "public void writeToParcel(Parcel dest, int flags)" when I'm writing the ArrayList:</p>
  
  <pre><code>dest.writeTypedList(attachments);
  </code></pre>
  
  <p>And what seems to be causing the error, in "private void readFromParcel(Parcel in)":</p>
  
  <pre><code>in.readTypedList(attachments, AttachmentsData.CREATOR); 
  </code></pre>
  
  <p>I've tried finding different ways of solving it and have tried some versions, one being:</p>
  
  <pre><code>in.readList(attachments, AttachmentsData.class.getClassLoader());
  </code></pre>
  
  <p>But the app crashes.. Does anyone have a clue what I'm doing wrong? Or rather, I'm obviously writing or reading the ArrayList in a way that's not correct, but what is the right way?</p>
  
  <p>Thanks,
  Kristina</p>
  
  <p><strong>EDIT</strong>
  I may just have solved it,
  I changed the in to</p>
  
  <pre><code>attachments = in.createTypedArrayList(AttachmentsData.CREATOR);
  </code></pre>
  
  <p>Seems to be working! I guess it may have the same effect as David Wasser's answer?</p>