NoSuchMethodError在Kotlin中使用@Parcelize批注 [英] NoSuchMethodError using @Parcelize Annotation in Kotlin

查看:452
本文介绍了NoSuchMethodError在Kotlin中使用@Parcelize批注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试实验性的(这可能是为什么它不起作用的原因...)@Parcelize注释以生成Parcelable代码.大多数类型似乎都可以正常工作,但是我遇到了Serializable抛出NoSuchMethodError的问题:

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)

我知道我可以通过将Date对象更改为String来解决此问题,但宁愿不这样做.除了使用Strings之外,还有其他人遇到可能提供可行解决方法的问题吗?

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

推荐答案

在SO上找不到任何内容,因此与其删除,我将其保留在这里以供参考,以防其他任何人碰到它.看来这已记录为影响1.1.4和1.1.50的错误 . (我使用的是1.1.4).

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).

看起来它已在1.1.6及更高版本中得到修复.

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

这篇关于NoSuchMethodError在Kotlin中使用@Parcelize批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆