Unable to initialize my MongoDB app since syncrootdirectory is null

19 Views Asked by At

I am unable to initialize my MongoDB App as my appfilesdirectory in building the app is null (i.e getting NullPointerException). How would I be able to fix this? I tried updating to the latest android studio gradle plugin and gradle version and tried different combinations yet none of them worked.

Here is the function code.

fun main() {
    val recommend = Recommend(BuildConfig.APP_ID)
    recommend.initializeRealm()
    recommend.printAllUsers()
    recommend.closeRealm()
    println("Hello World")
}

fun initializeRealm() {
        val app = App.create(realmAppId) //Where I get the error
        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 is the error in question:

Connected to the target VM, address: '127.0.0.1:42849', transport: 'socket'
Exception in thread "main" java.lang.ExceptionInInitializerError
    at io.realm.kotlin.mongodb.AppConfiguration$Builder.<init>(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.<clinit>(SystemUtilsAndroid.kt:19)
    ... 5 more
Disconnected from the target VM, address: '127.0.0.1:42849', transport: 'socket'

Process finished with exit code 1

Here is a picture of where the error occurs within the library files: Where error traces to

Here are also the variables and subclasses in which the Recommend class is tied to:

class Recommend(private val realmAppId: String) {
    @JsonIgnoreProperties(ignoreUnknown = true)
    data class YelpBusinessWIP(val name: String, val rating: Double, val location: YelpLocationWIP)

    @JsonIgnoreProperties(ignoreUnknown = true)
    data class YelpLocationWIP(
        val address1: String,
        val city: String,
        val state: String,
        val country: String
    )


    private var realm: Realm? = null
0

There are 0 best solutions below