NoSuchMethodError using @Parcelize Annotation in Kotlin

谁都会走 提交于 2019-12-12 10:45:57

问题


I'm currently trying out the experimental (which might be why it's not working...) @Parcelize annotation to generate Parcelable code. Most types seem to be working fine, but I'm having issues with Serializables throwing a 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)

I know I could fix this by changing the Date objects to Strings, but would rather not. Has anyone else run into this issue that could provide a viable workaround other than using Strings?

If needed, here's the implementation for reference:

@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

回答1:


Didn't find anything on SO, so rather than deleting I'll leave it here for reference incase anyone else runs into it. It looks like this has been logged as a bug that affects 1.1.4 and 1.1.50. (I was using 1.1.4).

Looks like it's been fixed for versions 1.1.6 and above.



来源:https://stackoverflow.com/questions/46592138/nosuchmethoderror-using-parcelize-annotation-in-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!