title: Problems in Parcelable Class using a List of Custom Objects (Defined in an Inner Class)
body: <p>I'm trying to make my class Parcelable, but I keep getting these errors:</p>
  
  <pre><code>    08-28 07:42:55.598    7810-7810/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.IllegalStateException: Could not execute method of the activity
          at android.view.View$1.onClick(View.java:3617)
          at android.view.View.performClick(View.java:4222)
          at android.view.View$PerformClick.run(View.java:17620)
          at android.os.Handler.handleCallback(Handler.java:800)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:194)
          at android.app.ActivityThread.main(ActivityThread.java:5391)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = thesleeplesselite.drgreenthumb.CropRotationPlan$SubPlan)
          at android.os.Parcel.writeSerializable(Parcel.java:1279)
          at android.os.Parcel.writeValue(Parcel.java:1233)
          at android.os.Parcel.writeList(Parcel.java:622)
          at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:248)
          at android.os.Parcel.writeParcelable(Parcel.java:1254)
          at android.os.Parcel.writeValue(Parcel.java:1173)
          at android.os.Parcel.writeMapInternal(Parcel.java:591)
          at android.os.Bundle.writeToParcel(Bundle.java:1627)
          at android.os.Parcel.writeBundle(Parcel.java:605)
          at android.content.Intent.writeToParcel(Intent.java:6850)
          at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
          at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
          at android.app.Activity.startActivityForResult(Activity.java:3388)
          at android.app.Activity.startActivityForResult(Activity.java:3349)
          at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
          at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.io.NotSerializableException: thesleeplesselite.drgreenthumb.CropRotationPlan
          at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
          at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
          at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
          at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at android.os.Parcel.writeSerializable(Parcel.java:1274)
              at android.os.Parcel.writeValue(Parcel.java:1233)
              at android.os.Parcel.writeList(Parcel.java:622)
              at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:248)
              at android.os.Parcel.writeParcelable(Parcel.java:1254)
              at android.os.Parcel.writeValue(Parcel.java:1173)
              at android.os.Parcel.writeMapInternal(Parcel.java:591)
              at android.os.Bundle.writeToParcel(Bundle.java:1627)
              at android.os.Parcel.writeBundle(Parcel.java:605)
              at android.content.Intent.writeToParcel(Intent.java:6850)
              at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
              at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
              at android.app.Activity.startActivityForResult(Activity.java:3388)
              at android.app.Activity.startActivityForResult(Activity.java:3349)
              at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
              at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here's the structure of my class; it has an inner class. I don't think it's ideal to put my entire code. It's just too long.</p>
  
  <pre><code>public class CropRotationPlan implements Parcelable {
  
      String name; // Name of plan
      HashMap&lt;String, List&lt;HashMap&lt;String, String&gt;&gt;&gt; listOfFamilies; // HashMap containing Plant Family Names as keys and a List of plants
      List&lt;SubPlan&gt; listOfSubPlans;
  
      public CropRotationPlan() {
          name = null;
          listOfFamilies = new HashMap&lt;&gt;();
          listOfSubPlans = new ArrayList&lt;&gt;();
      }
  
      ...
  
      @Override
      public int describeContents() {
          return 0;
      }
  
      @Override
      public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(this.name);
          dest.writeSerializable(this.listOfFamilies);
          dest.writeList(this.listOfSubPlans);
      }
  
      protected CropRotationPlan(Parcel in) {
          this.name = in.readString();
          this.listOfFamilies = (HashMap&lt;String, List&lt;HashMap&lt;String, String&gt;&gt;&gt;) in.readSerializable();
          this.listOfSubPlans = new ArrayList&lt;SubPlan&gt;();
          in.readList(this.listOfSubPlans, List.class.getClassLoader());
      }
  
      public static final Parcelable.Creator&lt;CropRotationPlan&gt; CREATOR = new Parcelable.Creator&lt;CropRotationPlan&gt;() {
          public CropRotationPlan createFromParcel(Parcel source) {
              return new CropRotationPlan(source);
          }
  
          public CropRotationPlan[] newArray(int size) {
              return new CropRotationPlan[size];
          }
      };
  
      public class SubPlan implements Serializable {
          int year;
          HashMap&lt;String, Integer&gt; orderOfFamilies;
          ...
      }
  }
  </code></pre>
  
  <p>At this point, I seriously have no idea what to do. </p>
  
  <p><code>CropRotationPlan.java:248</code> is <code>dest.writeList(this.listOfSubPlans);</code> in <code>writeToParcel()</code></p>
  
  <p>Also, in another class, I have this method:</p>
  
  <pre><code>public void btnViewPlan(View view) {
      // We'll be sending our cropRotationPlan object to next activity (PlanActivity)
      // And we'll be expecting a result (since we'll allow the user to manipulate the object there)
      Intent i = new Intent(CropRotationPlannerActivity.this, PlanActivity.class);
      i.putExtra("cropRotationPlan", cropRotationPlan);
      startActivityForResult(i, SET_PLAN_REQUEST);
  }
  </code></pre>
  
  <p><code>CropRotationPlannerActivity.java:197</code> is: <code>startActivityForResult(i, SET_PLAN_REQUEST);</code></p>
  
  <p>I've tried placing my inner class into a separate class, and then had it to implement <code>Serializable</code> OR <code>Parcelable</code> (just one of 'em) but I just keep getting errors. All relating to my <code>SubPlan</code> class; like problems with marshing it and stuff. Along with using <code>TypedList</code> instead somewhere in the code. </p>
  
  <p>Help would be appreciated. Thanks!</p>
  
  <p>I just don't know what to do anymore.</p>
  
  <p>PS: I'm sorry if I sound so incoherent right now. I might edit this post once I recover my sanity.</p>
  
  <p><strong>CODE FOR <code>SubPlan</code> CLASS</strong></p>
  
  <pre><code>public class SubPlan implements Serializable {
          int year;
          HashMap&lt;String, Integer&gt; orderOfFamilies;
  
          public SubPlan(int year) {
              orderOfFamilies = new HashMap&lt;&gt;();
              this.year = year;
              int temp = -1;
              for (String key : listOfFamilies.keySet()) {
                  orderOfFamilies.put(key, ++temp);
              }
          }
  
          public SubPlan(int year, HashMap&lt;String, Integer&gt; orderOfFamilies) {
              this.year = year;
              this.orderOfFamilies = orderOfFamilies;
          }
  
          public int getYear() {
              return year;
          }
  
          public String getName() {
              return "Year " + year;
          }
  
          public String getKey(int index) {
              for (String key : orderOfFamilies.keySet()) {
                  if (orderOfFamilies.get(key).equals(index))
                      return key;
              }
              return null;
          }
  
          public int getLocationOf(String family) {
              return orderOfFamilies.get(family);
          }
  
          public void setOrderOfFamily(String family, int index) {
              if (orderOfFamilies.containsKey(family))
                  orderOfFamilies.put(family, index);
          }
  
          public void removeFamily(String family) {
              if (orderOfFamilies.containsKey(family)) {
                  orderOfFamilies.remove(family);
              }
          }
  
          public void rotateFamilies() {
              for (int i = 0; i &lt; getNumberOfFamilies(); i++) {
                  String family = getKey(i);
                  // if not last family on list
                  if (orderOfFamilies.get(family) != getNumberOfFamilies() - 1)
                      setOrderOfFamily(family, i + 1);
                  else
                      setOrderOfFamily(family, 0);
              }
          }
      }
  </code></pre>
  
  <p>Additionally, <code>getNumberOfFamilies()</code> is a method belonging to the parent class, with the following definition: </p>
  
  <pre><code>    public int getNumberOfFamilies() {
          return listOfFamilies.size();
      }
  </code></pre>
  
  <p>I have initially not let <code>SubPlan</code> implement <code>Serializable</code> and these are the exceptions I get:</p>
  
  <pre><code>    08-28 08:31:07.809    8741-8741/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.IllegalStateException: Could not execute method of the activity
              at android.view.View$1.onClick(View.java:3617)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.reflect.InvocationTargetException
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.RuntimeException: Parcel: unable to marshal value thesleeplesselite.drgreenthumb.CropRotationPlan$SubPlan@4191f010
              at android.os.Parcel.writeValue(Parcel.java:1235)
              at android.os.Parcel.writeList(Parcel.java:622)
              at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:249)
              at android.os.Parcel.writeParcelable(Parcel.java:1254)
              at android.os.Parcel.writeValue(Parcel.java:1173)
              at android.os.Parcel.writeMapInternal(Parcel.java:591)
              at android.os.Bundle.writeToParcel(Bundle.java:1627)
              at android.os.Parcel.writeBundle(Parcel.java:605)
              at android.content.Intent.writeToParcel(Intent.java:6850)
              at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
              at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
              at android.app.Activity.startActivityForResult(Activity.java:3388)
              at android.app.Activity.startActivityForResult(Activity.java:3349)
              at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
              at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
  08-28 08:31:09.543     531-1643/? E/InputDispatcher﹕ channel '41d34990 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
  08-28 08:31:09.543     531-1643/? E/InputDispatcher﹕ channel '4281f970 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.CropRotationPlannerActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
  </code></pre>
  
  <p>Additionally, I have tried implementing <code>Parcelable</code> on <code>SubPlan</code> and made it have its own class:</p>
  
  <pre><code>08-28 08:54:59.291    9245-9245/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  java.lang.IllegalStateException: Could not execute method of the activity
          at android.view.View$1.onClick(View.java:3617)
          at android.view.View.performClick(View.java:4222)
          at android.view.View$PerformClick.run(View.java:17620)
          at android.os.Handler.handleCallback(Handler.java:800)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:194)
          at android.app.ActivityThread.main(ActivityThread.java:5391)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
          at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at android.view.View$1.onClick(View.java:3612)
              at android.view.View.performClick(View.java:4222)
              at android.view.View$PerformClick.run(View.java:17620)
              at android.os.Handler.handleCallback(Handler.java:800)
              at android.os.Handler.dispatchMessage(Handler.java:100)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5391)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
              at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
              at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.StackOverflowError
          at java.io.SerializationHandleMap.get(SerializationHandleMap.java:63)
          at java.io.ObjectOutputStream.dumpCycle(ObjectOutputStream.java:425)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1566)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at java.util.HashMap.writeObject(HashMap.java:1015)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
          at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at java.util.ArrayList.writeObject(ArrayList.java:644)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
          at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at java.util.HashMap.writeObject(HashMap.java:1016)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:525)
          at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
          at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
          at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
          at android.os.Parcel.writeSerializable(Parcel.java:1274)
          at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:185)
          at android.os.Parcel.writeParcelable(Parcel.java:1254)
          at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
          at android.os.Parcel.writeTypedList(Parcel.java:1017)
          at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:186)
          at android.os.Parcel.writeParcelable(Parcel.java:1254)
          at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
          at android.os.Parcel.writeTypedList(Parcel.java:1017)
          at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:186)
          at android.os.Parcel.writeParcelable(Parcel.java:1254)
          at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
          at android.os.Parcel.writeTypedList(Parcel.java:1017)
          at thesleeplesselite.drgreenthumb.CropRotationPlan.write
  </code></pre>