我正在使用房间数据库将数据存储在我的应用程序中。但是,在试图编译该项目时,我得到了以下错误:;无效的查询参数"。我试图在官方文件中找到原因,也在谷歌上搜索这个错误的原因,但都无济于事请你解释一下这个错误是什么,是什么原因造成的,以及我需要在项目中修复什么
准确的错误消息
C:Users***ParsedDatabase.java:10: error: Invalid query argument: int. It must be a class or an interface.
public final class ParsedDatabase {
^
模型-解析数据库(房间数据库实体,有问题的类(
@Entity(tableName = "parsed_database")
data class ParsedDatabase(
@PrimaryKey()
val id: Int = 1,
@ColumnInfo(name = "app_config")
val appConfigSection: HashMap<String, String>,
@ColumnInfo(name = "loans")
val loansList: ArrayList<Offer>,
@ColumnInfo(name = "cards")
val cardsList: ArrayList<ArrayList<Offer>>,
@ColumnInfo(name = "credits")
val creditsList: ArrayList<Offer>,
) {
enum class AppConfigKeys {
app_config,
user_term_html,
extra_field_,
}
enum class LoansAndCreditsKeys {
loans,
credits,
}
enum class CardsKeys {
cards,
}
}
刀类(我附上以防万一(
@Dao
interface LocalDatabaseDao {
@Insert(onConflict = REPLACE)
fun save(parsedDatabase: ParsedDatabase)
@Query("SELECT * FROM parsed_database WHERE id = :id")
fun load(id: Int = 1): ParsedDatabase?
@Delete
fun delete(parsedDatabase: ParsedDatabase)
@Delete(entity = ParsedDatabase::class)
fun delete(id: Int = 1)
}
数据库类
@Database(entities = [ParsedDatabase::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class LocalDatabase : RoomDatabase() {
abstract fun getLocalDatabaseDao(): LocalDatabaseDao
}
@Delete(entity = ParsedDatabase::class)
fun delete(id: Int = 1)
我认为Room不知道该怎么办。如果你需要这种操作,你可以尝试:
@Query("DELETE FROM parsed_database WHERE id = :id")
fun delete(id: Int = 1)