Error when copying database from solutions file if you did Ch. 9 Challenge

I copied the database files to my emulator and upon starting the app, I received the following runtime error

2019-09-25 09:25:31.190 4511-4526/? E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0
Process: edu.mines.criminalintentbnr4k, PID: 4511
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:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)
 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:266)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
    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)
    at androidx.room.util.DBUtil.query(DBUtil.java:54)
    at com.criminalintentbnr4k.database.CrimeDao_Impl$1.call(CrimeDao_Impl.java:38)
    at com.criminalintentbnr4k.database.CrimeDao_Impl$1.call(CrimeDao_Impl.java:35)
    at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:90)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
    at java.lang.Thread.run(Thread.java:761) 

Upon inspection of the generated Java code and the existing database schema, the provided database file does not contain a column for the requiresPolice field that was added from the Chapter 9 challenge.

If you’re working through the book, then make sure you undo this challenge when using the prepopulated database file. I think one of the best features of this book is carrying the challenges through since to continue patching the additions you need to have a strong understanding of the topics presented in each chapter. I realize this is temporary since at this point we don’t have the features yet to popualte the database, it’s just unfortunate to need to undo a prior step.

1 Like

Confirmed. Thanks for sharing this. Definitely saved me hours of fiddling around.

I haven’t read the Android Programming book, but in the book I am currently working through (for iOS Programming) the authors explicitly tell you not to carry forward the code you write for the challenges into subsequent chapters, but to make a copy of the code to do the challenges with. Since the authors can’t know exactly how you’ll choose to implement the challenge code, it’s hard for them to build on that in subsequent chapters; I think that’s why they try to avoid the issue entirely.

1 Like

Good to know! I must have missed it. In this iOS book do they say that every challenge chapter? Or was that part of the introduction somewhere.

In the first chapter that has challenges, they have a couple paragraphs that talk about the purpose of the challenges & how they work. They don’t mention it again in subsequent chapters.