在上篇文Activity间传类对象数据中的person类中加入一个List字段的话,如下
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 marshalled representation. //CONTENTS_FILE_DESCRIPTOR @Override public int describeContents() { // TODO Auto-generated method stub return 0; } //该方法将类的数据写入外部提供的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 必须要指明 } }List中是什么类型就要把类型的class loader引入,否则就会报上述错误。