我目前正在尝试实验(可能是为什么它不起作用……)@Parcelize注释来生成Parcelable代码.大多数类型似乎工作正常,但我遇到Serializables抛出NoSuchMethodError的问题:
10-05 13:55:18.549 20808-20808/com.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app,PID: 20808 java.lang.NoSuchMethodError: No virtual method writeSerializable(Ljava/util/Date;)V in class Landroid/os/Parcel; or its super classes (declaration of 'android.os.Parcel' appears in /system/framework/framework.jar) at com.app.models.Job.writeToParcel(Job.kt) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3082) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518) at android.app.Activity.startActivityForResult(Activity.java:4225) at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65) at android.app.Activity.startActivityForResult(Activity.java:4183) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711) at android.app.Activity.startActivity(Activity.java:4522) at android.app.Activity.startActivity(Activity.java:4490)
我知道我可以通过将Date对象更改为字符串来解决这个问题,但不愿意.有没有其他人遇到这个问题,除了使用字符串之外,还可以提供一个可行的解决方法?
如果需要,这里是参考的实现:
@Parcelize data class Job(val id: String,val description: String,val state: String,val job_type: String?,val close_on: Date?,val posted_on: Date?) : Parcelable