1

I am getting below error while passing custom Arraylist in intent.

  Parcel: unable to marshal value com.kahoindia.dev.models.KaHOStudentModel@62bceea

This is how am passing

KaHOSelectedObj selObject = new KaHOSelectedObj(); /*Parcelable */
                selObject.setmIntent(mContext);
                selObject.setSelectedStudents(mSelectedStudents);
                Intent intent = new Intent(mContext, KaHOMyInputsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putParcelable("SelectedStudents", selObject);
                intent.putExtras(bundle);
                startActivity(intent);

I am using Parcelable, but am getting unable to marshall.. run time error in the calling function at line start activity. Please help how to proceed with!

public class KaHOSelectedObj implements Parcelable
{
    private Context mIntent;
    private ArrayList<KaHOStudentModel> mSelectedStudentObj;

    public Context getmIntent() {
        return mIntent;
    }

    public void setmIntent(Context mIntent) {
        this.mIntent = mIntent;
    }

    public ArrayList<KaHOStudentModel> getSelectedStudents() {
        return mSelectedStudentObj;
    }

    public void setSelectedStudents(ArrayList<KaHOStudentModel> mObjects) {
        this.mSelectedStudentObj = mObjects;
    }


    public static final Parcelable.Creator<KaHOSelectedObj> CREATOR = new Creator<KaHOSelectedObj>() {
        @Override
        public KaHOSelectedObj createFromParcel(Parcel source) {
            KaHOSelectedObj selObj = new KaHOSelectedObj();
            selObj.mSelectedStudentObj = source.readArrayList(null);
            return selObj;
        }
        @Override
        public KaHOSelectedObj[] newArray(int size) {
            return new KaHOSelectedObj[size];
        }
    };
    @Override
    public int describeContents() {
        return 0;
    }
    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeList(mSelectedStudentObj);
    }
}
Karthik Thunga
  • 1,093
  • 2
  • 12
  • 21
  • did it show some suggestion in KaHOSelectedObj class – Muhammad Younas Aug 09 '16 at 05:12
  • 1
    no its not showing – Karthik Thunga Aug 09 '16 at 05:15
  • 1
    `KaHOStudentModel` must implement `Parcelable`, too. – Mike M. Aug 09 '16 at 05:19
  • 2
    Possible duplicate of [how to properly implement Parcelable with an ArrayList?](http://stackoverflow.com/questions/7042272/how-to-properly-implement-parcelable-with-an-arraylistparcelable) – Kushan Aug 09 '16 at 05:51
  • As with serializable, Parcealable also requires all the child members of a Parceable Object to also be Parcealable... Thus KaHoStudentModel must also be Parcealable...check : http://stackoverflow.com/questions/7042272/how-to-properly-implement-parcelable-with-an-arraylistparcelable – Kushan Aug 09 '16 at 05:52

0 Answers0