google-developer-training/android-basics-kotlin-inventory-app

Android Basics: Read and update data with Room - Crashing when saving to DB initially

Closed this issue · 0 comments

https://developer.android.com/codelabs/basic-android-kotlin-training-update-data-room?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-5-pathway-2%3Fhl%3Den%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-update-data-room&hl=en#1

When running the code from the room branch for the first time, it compiled and ran fine. However when I tried to save an item, it would crash. The logcat said the DB schema had changed and the version number needed to be updated. I went into ItemRoomDatabase.kt and updated version = 2 and the code worked as expected. FYI.