My class PhotosList:
public class PhotosList extends DataList<Photo> {
public PhotosList() {}
@SuppressWarnings("unused")
public PhotosList(Parcel source) {
super(source);
items = new ArrayList<>();
source.readList(items, Photo.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeList(items);
}
...
My class Photo:
public class Photo extends BaseModel {
@SerializedName("photos")
public ArrayList<Image> images;
@SuppressWarnings("unused")
public Photo() {}
@SuppressWarnings("unused")
public Photo(Parcel source) {
super(source);
images = new ArrayList<>();
source.readList(images, Image.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeList(images);
}
...
My class DataList:
public class DataList<T> implements Parcelable {
@SerializedName("total_count")
public int total;
@SerializedName("message")
public String message;
@SerializedName("items")
public ArrayList<T> items;
@SuppressWarnings("unused")
public DataList() {}
@SuppressWarnings("unused")
public DataList(Parcel source) {
total = source.readInt();
message = source.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(total);
dest.writeString(message);
}
And I have this error:
Class not found when unmarshalling: com.xxx.model.PhotosList java.lang.ClassNotFoundException: com.xxx.model.PhotosList at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:324) at android.os.Parcel.readParcelableCreator(Parcel.java:2404) at android.os.Parcel.readParcelable(Parcel.java:2358) at android.os.Parcel.readValue(Parcel.java:2264) at android.os.Parcel.readArrayMapInternal(Parcel.java:2614) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.getString(BaseBundle.java:920) at android.content.Intent.getStringExtra(Intent.java:6183) at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:2707) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:2169) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:6322) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:6100) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:170) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3990) at android.os.Binder.execTransact(Binder.java:453) Caused by: java.lang.ClassNotFoundException: com.xxx.model.PhotosList at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:324) at android.os.Parcel.readParcelableCreator(Parcel.java:2404) at android.os.Parcel.readParcelable(Parcel.java:2358) at android.os.Parcel.readValue(Parcel.java:2264) at android.os.Parcel.readArrayMapInternal(Parcel.java:2614) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.getString(BaseBundle.java:920) at android.content.Intent.getStringExtra(Intent.java:6183) at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:2707) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:2169) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:6322) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:6100) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:170) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3990) at android.os.Binder.execTransact(Binder.java:453) Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I get back the photolist object like that:
getIntent().setExtrasClassLoader(PhotosList.class.getClassLoader());
PhotosList photosList = bundle.getParcelable(BUNDLE_KEY_PHOTOS);
Parcelable
objects work in some cases and not in others. Basically, foreign processes cannot work with them, because they do not have access to your class. See this blog post. It is unclear wherebundle
comes from and where exactly the crash is occurring. – CommonsWare