I’m trying to setup and use Realm Sync with my Android Application. This is the function that I’ve written in order to try and open up the realm, but I’m getting this ExceptionInInitializer Error. Is there any specific code that I need to trigger to initialize Realm before calling this code:
private fun openSyncRealm() {
val app = App.create(APP_ID)
runBlocking {
try {
val user = app.currentUser
val config = SyncConfiguration.Builder(
user = user!!,
partitionValue = "123456789",
schema = setOf(AuthenticatedUser::class)
).name(name = "user").build()
val realm = Realm.open(config)
Log.d("PreparationScreen", "Successfully opened realm: ${realm.configuration.name}")
} catch (e: Exception) {
Log.d("PreparationScreen", "$e")
}
}
}
And this is my RealmObject subclass:
class AuthenticatedUser: RealmObject {
@PrimaryKey
val _id: ObjectId = ObjectId.create()
var _partition: String = "userId=$_id"
var name: String = ""
}
Config Builder is causing the error:
java.lang.ExceptionInInitializerError at java.lang.reflect.Field.get(Native Method) at kotlin.reflect.jvm.internal.KClassImpl$Data$objectInstance$2.invoke(KClassImpl.kt:117) at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:63) at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32) at kotlin.reflect.jvm.internal.KClassImpl$Data.getObjectInstance(KClassImpl.kt:108) at kotlin.reflect.jvm.internal.KClassImpl.getObjectInstance(KClassImpl.kt:242) at kotlin.reflect.full.KClasses.getCompanionObjectInstance(KClasses.kt:57) at io.realm.kotlin.internal.platform.RealmObjectKt.realmObjectCompanionOrNull(RealmObject.kt:27) at io.realm.kotlin.Configuration$SharedBuilder.(Configuration.kt:389) at io.realm.kotlin.mongodb.sync.SyncConfiguration$Builder.(SyncConfiguration.kt:213) at io.realm.kotlin.mongodb.sync.SyncConfiguration$Builder.(SyncConfiguration.kt:313) at com.example.feature.authentication.presentation.preparation.PreparationScreenKt$openSyncRealm$1.invokeSuspend(PreparationScreen.kt:61)
from Mongo DB Realm - java.lang.ExceptionInInitializerError
No comments:
Post a Comment