realm-java: Cannot be cast to io.realm.FooRealmProxyInterface
Goal
Simply load data, I’m using
Kotlin 1.0.4
andminifyEnabled
Result
ClassCastException when it tries to do a query.
Steps & Code to Reproduce
It happens randomly, the code sample is below.
Code Sample
fun insertOrUpdate(taskQueue: TaskQueue?, realm: Realm?) {
try {
realm?.run {
executeTransaction {
taskQueue?.let {
insertOrUpdate(it)
}
}
}
} catch (e: Exception) {
if (DEBUG_ENABLED) {
e.printStackTrace()
}
Crashlytics.logException(e)
}
}
open class TaskQueue(
@PrimaryKey var id: String,
var layers: RealmList<Layer> = RealmList()):
RealmObject(), Parcelable {
companion object {
@JvmField val CREATOR = object : Parcelable.Creator<TaskQueue> {
override fun createFromParcel(source: Parcel) = TaskQueue(source)
override fun newArray(size: Int): Array<TaskQueue?> = arrayOfNulls(size)
}
}
//...Parcel and more not important
}
Version of Realm and tooling
Realm version(s): 2.2.1 Realm sync feature enabled: No Android Studio version: 2.1.2 / gradle-2.14.1 Which Android version and device: 6.0 - LG G2
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 24 (8 by maintainers)
Does adding
@RealmClass
annotation toTaskQueue
class solve the issue? https://realm.io/docs/java/latest/#kotlinHad the same problem. It was solved by 3 steps: 1. Clean the project 2. Clear app data/cache 3.Uninstall/install app
@zaki50 doesn’t work for me. Still get
after adding
@RealmClass
with Gradle 3.2. On Gradle 3.1 works ok even without@RealmClass
.you apply
kotlin-android
beforerealm-android
, right?