gpt4 book ai didi

android - 类型不匹配 : inferred type is AutoMigration but KClass<*> was expected

转载 作者:行者123 更新时间:2023-12-04 11:35:03 26 4
gpt4 key购买 nike

我试图实现一个简单的自动迁移,它只是将一个可为空的字符串字段添加到我唯一的表中,但由于某种原因,我在 autoMigrations = [AutoMigration(from = 1, to = 2)] 中收到以下错误线:

Type mismatch: inferred type is AutoMigration but KClass<*> was expected


我说这是一个奇怪的错误,因为即使是 documentation has it this way.
完整代码如下:
@Database(
version = 2,
entities = [Note::class],
autoMigrations = [AutoMigration(from = 1, to = 2)]
)
@TypeConverters(Converters::class)
abstract class NotesDB : RoomDatabase() {
abstract fun noteDao(): NoteDao

companion object {
@Volatile
private var INSTANCE: NotesDB? = null

fun getDB(context: Context): NotesDB {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
NotesDB::class.java,
"notesDB"
).build()
INSTANCE = instance
instance
}
}
}
}

最佳答案

将 build.gradle 中的房间版本更改为最新版本(目前为 2.4.0-alpha04)。然后,如果您收到有关 room.schemaLocation 的错误,请查看此答案 https://stackoverflow.com/a/44424908/6568162

关于android - 类型不匹配 : inferred type is AutoMigration but KClass<*> was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68242053/

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