Add a List field to the person class in the data of the class object in the previous article Activity, as shown below:
Package com. linc. meta; import android. OS. parcel; import android. OS. parcelable; public class Person implements Parcelable {private String Name = null; private String Gender = null; private int HP = 0; private String Summary = null; private String Skill = null; private List <String> skillList = new ArrayList <String> (); public Person (String name, String gender, int HP, String summary, String skill) {this. name = name; this. gender = gender; this. summary = summary; this. HP = HP; this. skill = skill;} public String getName () {return Name;} public void setName (String name) {Name = name;} public String getGender () {return Gender ;} public void setGender (String gender) {Gender = gender;} public int getHP () {return HP;} public void setHP (int hP) {HP = hP ;} public String getSummary () {return Summary;} public void setSummary (String summary) {Summary = summary;} public String getSkill () {return Skill;} public void setSkill (String skill) {Skill = skill;} // Describe the kinds of special objects contained in this Parcelable's specified alled representation. // CONTENTS_FILE_DESCRIPTOR @ Override public int describeContents () {// TODO Auto-generated method stub return 0 ;} // This method writes the class data to the external provided Parcel @ Override public void writeToParcel (Parcel dest, int flags) {dest. writeString (Name); dest. writeString (Gender); dest. writeString (Summary); dest. writeInt (HP); dest. writeString (Skill);} public static final Parcelable. creator <Person> CREATOR = new Creator <Person> () {@ Override public Person createFromParcel (Parcel source) {return new Person (source );} @ Override public Person [] newArray (int size) {return new Person [size] ;}}; private Person (Parcel dest) {this. name = dest. readString (); this. gender = dest. readString (); this. summary = dest. readString (); this. HP = dest. readInt (); this. skill = dest. readString (); this. skillList = dest. readArrayList (String. class. getClassLoader (); // class loader must be specified }}
The class loader of the type should be introduced into the List. Otherwise, the above error will be reported.