将parcelable对象列表传递给一个新intent
的{{1}}时,我遇到了问题。
这就是我的所作所为:
activity
当我调用 startActivity 时,我收到以下错误:
Intent intent = new Intent(context, CurriculumCorsesActivity.class);
intent.setExtrasClassLoader(CurriculumCourseCard.class.getClassLoader());
intent.putParcelableArrayListExtra("courses", card.getCourses());
context.startActivity(intent);
CurriculumCourseCard 实现 Parcelable 界面。这是实施:
E/Parcel﹕ Class not found when unmarshalling: pt.tecnico.fenixmobile.person.CurriculumCourseCard, e: java.lang.ClassNotFoundException: pt.tecnico.fenixmobile.person.CurriculumCourseCard
这就是我在新活动中获取列表的方式:
public class CurriculumCourseCard implements Serializable, Parcelable{
private static final long serialVersionUID = 765578940083L;
private String courseName;
private String finalGrade;
private String ects;
public CurriculumCourseCard(Parcel in) {
this.courseName = in.readString();
this.finalGrade = in.readString();
this.ects = in.readString();
}
public String getCourseName() {
return courseName;
}
public String getFinalGrade() {
return finalGrade;
}
public String getEcts() {
return ects;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.courseName);
parcel.writeString(this.finalGrade);
parcel.writeString(this.ects);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public CurriculumCourseCard createFromParcel(Parcel in) {
return new CurriculumCourseCard(in);
}
public CurriculumCourseCard[] newArray(int size) {
return new CurriculumCourseCard[size];
}
};}
在新Intent intent = getIntent();
intent.setExtrasClassLoader(CurriculumCourseCard.class.getClassLoader());
ArrayList<CurriculumCourseCard> courses = intent.getParcelableArrayListExtra("courses");
中,我看到的内容与列表中的内容一样多,但根本没有内容。唯一的错误就是之前描述过的错误。
希望你能帮助我。