gpt4 book ai didi

android - Room Kotlin 找不到现场的二传手

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:01 25 4
gpt4 key购买 nike

您好,我正在尝试在基于 MVP 的项目中将 Room 与 Kotlin 结合使用。

我的问题是,当我创建一个数据类和相关的 DAO 时,所有类都会成功生成,但是当创建第二个数据类并且它是 DAO 时,Error:Cannot find setter for field. 在 android studio 中的重建命令中抛出

@Entity(tableName = "TB_CLASSES")
class TbClass(
@ColumnInfo(name = "ID")
@PrimaryKey(autoGenerate = true) var id: Int =-1,
@ColumnInfo(name = "NAME") var name: String="",
@ColumnInfo(name = "CAPTION") var caption: String="",
@ColumnInfo(name = "TYPE") var type: String="")

@Entity(tableName = "TB_FEATURE_DISA")
class TbFeatureDisa(
@ColumnInfo(name = "ID")
@PrimaryKey(autoGenerate = true) var id: Int=-1,
@ColumnInfo(name = "FEATURE_ID") var featureId: Int=-1,
@ColumnInfo(name = "DISA_ID") var disaId: Int=-1,
@ColumnInfo(name = "IS_SOLVED") var isSolved: Int=-1,
@ColumnInfo(name = "DISA_LEVEL") var disaLevel: Double=-0.1,
@ColumnInfo(name = "RESOLVER_USER_NAME") var resolverUserName: String="",
@ColumnInfo(name = "RESOLVE_TIME") var resolveTime: Date? =null,
@ColumnInfo(name = "REPORT_VIST_ID") var reportVisitId: Int=-1,
@ColumnInfo(name = "REPORT_FAULT_ID") var reportFaultId: Int=-1,
@ColumnInfo(name = "SOLVE_VIST_ID") var solveVisitId: Int=-1,
@ColumnInfo(name = "SOLVE_SERVICE_ID") var solveServiceId: Int=-1,
@ColumnInfo(name = "SOLVE_FUALT_ID") var solveFaultId: Int=-1)

我也检查过这个 link还有这个link但他们都不适合我

最佳答案

我终于找到了解决方案。问题与属性命名有关。

以下会导致编译时出错:

 @ColumnInfo(name = "IS_SOLVED") var isSolved 

但是当我把上面的改成下面的时候,错误就解决了:

 @ColumnInfo(name = "IS_SOLVED") var solved 

我们不能使用 SQLite 保留关键字 line用于字段命名。我使用的是 Room 版本 1.0.0 和 kotlin 版本 1.1.51。

关于android - Room Kotlin 找不到现场的二传手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48801444/

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