2 / 5
Jul 2024

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) }

It was a null pointer.

class HomeScreen : Screen { private var userNameSetSignIn = "" private var passwordSetSignIn = "" private var userNameSetSignUp = "" private var passwordSetSignUp = "" private var practiceSetSignUp = "" private var practiceSetSignIn = "" private var signUp = "Sign Up" private var signIn= "Sign In" @OptIn(ExperimentalResourceApi::class) @Preview @Composable override fun Content() { val navigator = LocalNavigator.currentOrThrow val showSignInNeededDialog = remember { mutableStateOf(false) } val showSignUpNeededDialog = remember { mutableStateOf(false) } val scrollState = rememberScrollState() val realm = RealmRepo
9 days later