gpt4 book ai didi

android - 房间 : Crash on emulator

转载 作者:行者123 更新时间:2023-11-29 22:55:32 36 4
gpt4 key购买 nike

我想为 pb 添加值,由于将 pb_value 包含到实体中,应用程序崩溃了。我是学习室的新手,我不确定将额外项目合并到数据库中的正确方法。

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

最佳答案

在我看来,您已经更改了数据库(即添加了 Pb),但尚未编写迁移,也未更改数据库版本号以显示这些数据库更改。我已经处理过几次这种崩溃,这就是它对我的意义。我一直在用 Java 工作,所以我不能真正告诉你如何在 Kotlin 中做到这一点(不过——尽管我希望很快就能实现),但这里是 Migrating Room databases 的指南来自 Android 开发者网站。

这非常简单,尽管 Room 还没有处理编写自己的迁移是一个真正的痛苦。不过,如果我没记错的话,Room 即将推出或正在开发的版本将解决此问题。

关于android - 房间 : Crash on emulator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57442895/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com