X类不是抽象的,并且没有实现android.os.Parcelable中定义的有趣的writeToParcel() [英] Class X is not abstract and does not implement fun writeToParcel() defined in android.os.Parcelable

查看:232
本文介绍了X类不是抽象的,并且没有实现android.os.Parcelable中定义的有趣的writeToParcel()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我想向我的Intent添加一个Bundle,其中包括如下所述的 Place 对象。由于可序列化很慢并且不建议使用,因此我更喜欢使用Parcelable。



虽然我使用Kotlin 1.3.31,但在打包某些数据类时遇到了问题。示例:

  import android.os.Parcelable 
import kotlinx.android.parcel.Parcelize

@Parcelize
数据类Place(val street:String,val postal:val,val city:String):可打包

和Android Studio抱怨:


类 Place不是抽象的,并且没有实现抽象成员
public abstract fun writeToParcel(p0:Parcel !, p1:Int):在android.os.Parcelable


根据一些教程


就是这样!您不再需要编写任何包裹方法!








我也进行了测试这类对象,它也可以正常工作:





旧答案



我正面临着同样的问题,而经调查,我发现:





所以看起来像从 Kotlin 1.3.40 开始, @Parcelize 注释将完全稳定。在此之前,您必须设置 experimental 标志。 (可悲)






他们错误地将 @Parcelize 推到了实验范围之外功能,您仍然会遇到该编译错误。


In my Android app, I want to add a Bundle including a Place object described below to my Intent. Since serializable was slow and not recommended, I preferred Parcelable.

Althoug I use Kotlin 1.3.31, I have problems parcelizing some data classes. Example:

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
data class Place(val street: String, val postal: String, val city: String) : Parcelable

and Android Studio complains:

Class 'Place' is not abstract and does not implement abstract member public abstract fun writeToParcel(p0: Parcel!, p1: Int): Unit defined in android.os.Parcelable

According to some tutorials

That’s it! You don’t need to write any parcel methods anymore!

https://android.jlelse.eu/yet-another-awesome-kotlin-feature-parcelize-5439718ba220

and I do not want to use

androidExtensions {
    experimental = true
}

in production stuff.

What alternatives would I have here?

解决方案

UPDATE 19/11/2019

After the stable release of Kotlin 1.3.60 and its corresponding Android Studio plugin the issue is no more. Let's celebrate

UPDATE 27/08/2019

After a bit of more researching and testing with the brand new Kotlin 1.3.50 seems that the issue is going to be finally fully addressed when they release Kotlin 1.3.60 as per this YouTrack issue

EDIT 19/06/2019

With Kotlin 1.3.40 release the @Parcelize annotation is out of experimental and works quite nicely. The only issue is a reported issue that makes the IDE go red, leaving this to a side the code does compile and run perfectly.

I have also tested with this kind of objects and it does also work:

Old answer

I'm facing the exact same issue and while investigating I found this:

So the looks like the @Parcelize annotation will be fully stable starting from Kotlin 1.3.40. Until then you will have to set the experimental flag. (Sadly)


They have wrongly pushed @Parcelize outside experimental features and you still get that compilation error.

这篇关于X类不是抽象的,并且没有实现android.os.Parcelable中定义的有趣的writeToParcel()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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