科特林-领域和包裹 [英] kotlin - realm and parcel
问题描述
我用android studio开发了android项目.
我想在Kotlin中使用onSaveInstanceState()
保存领域对象.
我的代码是
I develop the android project with android studio.
I want to save realm objects using onSaveInstanceState()
in kotlin.
My code is
@Parcel( implementations = arrayOf(UserRealmProxy::class),
value = Parcel.Serialization.BEAN,
analyze = arrayOf(User::class))
open class User : RealmObject() {
open var name: String? = null
@ParcelPropertyConverter(ListParcelConverter::class)
open var Items: RealmList<Item>? = null
}
但是编译时会出现一些错误:
but there are some errors while compiling:
'Unresolved reference: UserRealmProxy'
'An annotation parameter must be a compile-time constant'
当然,因为已经编译了项目,所以UserRealmProxy已经存在.
@ParcelPropertyConverter(ListParcelConverter::class)
也不起作用.
它会在运行时导致异常:
Sure, UserRealmProxy exists already because already the project has been compiled.
also @ParcelPropertyConverter(ListParcelConverter::class)
does not work.
it causes exception in runtime:
'java.io.NotSerializableException: io.realm.RealmList'
但是此代码在Java中编译良好.
But this code is compiled well in java.
我需要您的帮助.
推荐答案
在我的情况下,当出现以下错误时:'Unresolved reference:UserRealmProxy'.如果我有此包:com.path.model.Album,则必须使用:
In my case, when I have this error: 'Unresolved reference: UserRealmProxy'. If I have this package: com.path.model.Album, and I have to use:
import io.realm.com_path_model_AlbumRealmProxy
...
@Parcel(implementations = arrayOf(com_path_model_AlbumRealmProxy::class)
这篇关于科特林-领域和包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!