有时,我收到此错误,我不知道我的代码有什么问题请帮助!
任何建议代码都会有所帮助。
这是我的错误报告:
com.example E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: android.os.BadParcelableException: Parcelable protocol requires that the class implements Parcelable
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.os.BadParcelableException: Parcelable protocol requires that the class implements Parcelable
at android.os.Parcel.readParcelableCreator(Parcel.java:2407)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at android.view.AbsSavedState.<init>(AbsSavedState.java:57)
at android.view.View$BaseSavedState.<init>(View.java:22902)
at com.example.DrawableViewSaveState.<init>(DrawableViewSaveState.java:17)
at com.example.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:43)
at com.example.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:41)
这是我的 DrawableViewSaveState 类:
当我想回到使用 DrawableViewSaveState 类的活动时,就会发生此错误。我总是在 super(in) 中崩溃;
public class DrawableViewSaveState extends View.BaseSavedState {
private ArrayList<SerializablePath> paths;
public DrawableViewSaveState(Parcel in) {
super(in); // I'm always getting the crash in this line of code.
this.paths = (ArrayList<SerializablePath>) in.readSerializable();
for (SerializablePath p : paths) {
p.loadPathPointsAsQuadTo();
}
}
public DrawableViewSaveState(Parcelable parcelable) {
super(parcelable);
}
@Override public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(this.paths);
}
public ArrayList<SerializablePath> getPaths() {
return paths;
}
public void setPaths(ArrayList<SerializablePath> paths) {
this.paths = paths;
}
public static final Creator<DrawableViewSaveState> CREATOR =
new Creator<DrawableViewSaveState>() {
public DrawableViewSaveState createFromParcel(Parcel source) {
return new DrawableViewSaveState(source);
}
public DrawableViewSaveState[] newArray(int size) {
return new DrawableViewSaveState[size];
}
};
}