Hello, I have an issue with initializing my app to Atlas using Android Studio
I have been getting Initializer errors when running my program and I don’t know how to fix it.
I’ve tried upgrading my realm and kotlin versions in my top level build and that didn’t help. I tried upgrading my gradle plugins and that didn’t work.
Exception in thread “main” java.lang.ExceptionInInitializerError
at io.realm.kotlin.mongodb.AppConfiguration$Builder.(AppConfiguration.kt:162)
at io.realm.kotlin.mongodb.internal.AppImpl$Companion.create$io_realm_kotlin_library(AppImpl.kt:188)
at com.example.cuisinesync.AlgorithmAPIDB.Recommend.initializeRealm(WIPREC.kt:117)
at com.example.cuisinesync.AlgorithmAPIDB.WIPRECKt.main(WIPREC.kt:158)
at com.example.cuisinesync.AlgorithmAPIDB.WIPRECKt.main(WIPREC.kt)
Caused by: java.lang.NullPointerException
at io.realm.kotlin.internal.platform.SystemUtilsAndroidKt.(SystemUtilsAndroid.kt:19)
… 5 more
Process finished with exit code 1
This is the error I am getting.
The code in question:
fun initializeRealm() {
val app = App.create(realmAppId)
runBlocking {
try {
val user = app.login(Credentials.anonymous())
val schemaSet = setOf(User::class as KClass<out RealmObject>)
val syncConfig = SyncConfiguration.Builder(user, schema = schemaSet).build()
realm = Realm.open(syncConfig)
} catch (e: Exception) {
println("Error initializing Realm: ${e.message}")
}
}
}
Here’s the code that calls the function:
fun main() {
val recommend = Recommend(BuildConfig.APP_ID)
recommend.initializeRealm()
recommend.printAllUsers()
recommend.closeRealm()
I checked and made sure realmAppId Is not null.
I am having problems with line 162 within the AppConfig.kt file: