11

RuntimeException: Exception while computing database live data. FATAL EXCEPTION:...

 2 years ago
source link: http://i.lckiss.com/?p=7543
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

RuntimeException: Exception while computing database live data. FATAL EXCEPTION: arch_disk_io_0

2021-10-25

最近在写自己的一个小应用,开发了一段时间后,已经趋于稳定,但这些天对数据库进行 ADD COLUMN 操作时总报这样一个错:

E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0
java.lang.RuntimeException: Exception while computing database live data.
Caused by: java.lang.IllegalStateException: Migration didn't properly handle:

因为这方面的错误网上的内容实在不多,于是将目光转向自己的操作,直到今天才知道原因,原因是:

调用数据库的地方太早,早于 database ADD COLUMN 操作,至于为什么会早,主要是我喜欢用 Room 配合 LiveData 使用,并且将其定义为了成员变量,类似这样:

class ItemViewModel() : ViewModel(){
    private val itemDao = AppDatabase.getDatabase().itemDao()
    val liveData = itemDao.itemsLiveData()
    //...
}

以至于升级还未完成时, LiveData 已经在进行数据查询,导致抛出了这个错误。

终究是使用方式不对,以上。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK