I have some code that works great for Android and the emulator, but when I try to run it from the desktop it crashes with a null pointer exception. Can anyone see what it is I am doing wrong?
object RealmRepo {
lateinit var realm: Realm
var userEmail = ""
var practiceName = ""
private var initialized = false
private lateinit var registerPractice : Practice
private lateinit var userAccount : UserAccount
private val appServiceInstance by lazy {
// If logs are on app level then it set for everything ..
val configuration =
AppConfiguration.Builder("application-0-rpbsh")
.log(LogLevel.ALL).build()
App.create(configuration) //*** Null pointer happens here ***
}
init {
if (!initialized) {
setupRealmSync()
initialized = true
} else {
throw IllegalStateException("Singleton instance already created.")
}
}
private fun setupRealmSync() {
val user = runBlocking { appServiceInstance.currentUser!! }
val config = SyncConfiguration
.Builder(
user,
setOf(UserAccount::class,Pellet::class, PelletInsertionVisit::class, PelletLot::class, Patient::class,
Practice::class )
)
.initialSubscriptions(rerunOnOpen = true) { realms ->
add(
realms.query<PelletInsertionVisit>(),
name = "patient info",
updateExisting = true
)
add(realms.query<PelletLot>(), name = "Pellet info", updateExisting = true)
add(realms.query<Patient>(), name = "Patient info", updateExisting = true)
add(realms.query<Practice>(), name = "Practice info", updateExisting = true)
add(realms.query<UserAccount>(), name = "UserAccount info", updateExisting = true)
}
.build()
realm = Realm.open(config)
}