问题
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'
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'
But this code is compiled well in java.
i need your help.
回答1:
Probably, you will annotate to setter. Please try this.
@Parcel( implementations = arrayOf(UserRealmProxy::class),
value = Parcel.Serialization.BEAN,
analyze = arrayOf(User::class))
open class User : RealmObject() {
open var name: String? = null
open var Items: RealmList<Item>? = null
@ParcelPropertyConverter(ListParcelConverter::class) set
}
回答2:
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)
来源:https://stackoverflow.com/questions/38910246/kotlin-realm-and-parcel