0

I want to add the value for pb and since including pb_value into the entity, the application crashes. I am new to learning room and I am not sure of the correct way to incorporate the extra item into the database.

E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0

    java.lang.RuntimeException: Exception while computing database live data.
        at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
        at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:139)
        at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:119)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:142)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:409)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
        at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:452)
        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:275)
        at androidx.room.RoomDatabase.query(RoomDatabase.java:304)
@Entity(tableName = "pb_table")
data class Pb(@PrimaryKey
              val pb: String,
              val pb_value: Double
              )
@Dao
interface PbDao {

    @Query("SELECT * from pb_table ORDER BY pb ASC")
    fun getListPbs(): LiveData<List<Pb>>


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(pb: Pb)


    @Query("DELETE FROM pb_table")
    suspend fun deleteAll()
SK1dev
  • 1,049
  • 1
  • 20
  • 52
  • Use Logcat to examine the stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this If you do not understand how to resolve the problem, edit your question and provide the complete stack trace. – CommonsWare Aug 10 '19 at 14:13

1 Answers1

0

It looks to me like you've changed your database (ie added Pb) and haven't yet written a migration nor changed your database version number to show these database changes. I've dealt with this kind of crash a few times and that's what it's always meant for me. I've been working in Java, so I couldn't really tell you how to do it in Kotlin (yet-- though I'm hoping to make the jump soon), but here's the guide to Migrating Room databases from the Android Developer's site.

It's pretty straightforward, though it's a real pain in the butt that Room doesn't handle writing its own migrations yet. If I remember correctly there is a version coming up soon proposed or in development for Room that will fix this issue, though.

  • Thanks a lot. I will take a look at Migration. I am new to coding so there's a lot to take in but hopefully this will help fix it. – SK1dev Aug 10 '19 at 14:28
  • I've included migration but unfortunately that didn't fix it. – SK1dev Aug 10 '19 at 15:14
  • 1
    Did you increment the version number in `AppDatabase` and/or any associated database code files? – Damon Getsman Aug 10 '19 at 19:02
  • Yes I did that too. – SK1dev Aug 10 '19 at 19:04
  • 1
    Any chance you could post the whole of the involved code for better troubleshooting? Also, if I'm not able to help you out here and others don't come along that are more knowledgeable in _Room_ than I, you may want to try [AndroidForums](http://androidforums.com); I know there's at least a couple of people there willing to troubleshoot _Room_ issues, even if they don't have much experience with it. – Damon Getsman Aug 10 '19 at 21:03
  • That's very helpful, thank you. I'm not sure what I did, but I got it working again by changing a few things. I know it sounds silly but it's fixed :) Next I want to add the value, date and details for the pb but I'm having a few errors on this now. I will post a new question and if you could have a look that would be great. – SK1dev Aug 10 '19 at 21:21
  • Thanks for the link, it's great. – SK1dev Aug 10 '19 at 22:17