title: Error with unpacking a Custom Data Type from a Parcel in Android
body: <p>I have this problem of recreating an array of a custom data type after it was written to a parcel.</p>
  
  <p>playerwear is declared as such:</p>
  
  <pre><code>private Wearable playerWear[] = new Wearable[5];
  </code></pre>
  
  <p>This is the lines that write it to a parcel in the parent class.
  It is an array of type Wearable with 5 elements</p>
  
  <pre><code>        parcel.writeArray(playerWear);
  </code></pre>
  
  <p>This is the line that reads it from the Parcel (temp is an empty data element of the parent and has all elements filled in the same fashion as bellow.  All others are working)</p>
  
  <pre><code>        temp.playerWear = (Wearable[])source.readArray(Wearable.class.getClassLoader());
  </code></pre>
  
  <p>Here is the code of the Parcel Interface that are defined in the Wearable datatype:</p>
  
  <pre><code>    @Override
  public int describeContents()
  {
      return 0;
  }
  
  /**
   * This is the main method of the Parcelable Interface.  This packs everything
   * up into the parcel that will be used in the next activity
   * @param parcel the parcel that will be passed to the next activity
   * @param i used to keep track of the size...I think
   */
  @Override
  public void writeToParcel(Parcel parcel, int i)
  {
      parcel.writeString(slotName);
      parcel.writeParcelable(heldItem, i);
      if (holdingItem)
          parcel.writeString("True");
      else
          parcel.writeString("False");
  }
  
  /**
   * This is the method that takes the passed parcel and rebuilds it so that it can be used
   * @param source the passed parcel
   * @return the reconstructed data type
   */
  public static Wearable recreateParcel(Parcel source)
  {
      Wearable temp = new Wearable();
      temp.slotName = source.readString();
      temp.heldItem = (Item) source.readParcelable(Item.class.getClassLoader());
      String bool = source.readString();
      if(bool.equals("True"))
          temp.holdingItem = true;
      else
          temp.holdingItem = false;
  
      return temp;
  }
  
  /**
   * Not truly sure what this is but I think this is similar to the classLoader
   */
  public static final Parcelable.Creator CREATOR = new Parcelable.Creator()
  {
      /**
       * Calls the method that I created to recreate the Data type
       * @param in the passed parcel
       * @return s the return of the recreateParcel method
       */
      public Wearable createFromParcel(Parcel in)
      {
          return recreateParcel(in);
      }
  
      /**
       * Called if the custom data type is in an array
       * @param size the size of the array. Used to figure out how many elements are needed
       * @return an Array of the Data type
       */
      public Wearable[] newArray(int size)
      {
          return new Wearable[size];
      }
  };
  </code></pre>
  
  <p>Lastly this is the error that it is giving me,</p>
  
  <blockquote>
    <p>Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to com.rtbd.storytime.Wearable[]</p>
  </blockquote>
  
  <p>Please post if I forgot any vital information that is needed to solve this problem.  </p>
  
  <p>Thanks!</p>