科特林房间无法找到场地的二传手

时间:2018-02-15 06:54:19

标签: android kotlin android-room

您好我在基于Kotlin的项目中尝试使用MVP的会议室。

我的问题是,当我创建一个数据类并且相关DAO时,所有类都会成功生成,但是当创建第二个数据类并且它DAO { {1}} 在android studio

中的rebuild命令上抛出
Error:Cannot find setter for field.

我还检查了这个linklink,但这些都没有为我工作

3 个答案:

答案 0 :(得分:3)

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

以下内容在编译时导致错误:

 @ColumnInfo(name = "IS_SOLVED") var isSolved 

但当我将上述内容更改为以下内容时,错误已解决:

 @ColumnInfo(name = "IS_SOLVED") var solved 

我们不能使用SQLite保留关键字line进行字段命名。 我正在使用Room版本1.0.0和kotlin版本1.1.51。

答案 1 :(得分:2)

创建一个data class,其中提供settersgetters属性,如

@Entity(tableName = "TB_CLASSES")
data class TbClass( //< add data prior to class
@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="")

<强> TbFeatureDisa

    @Entity(tableName = "TB_FEATURE_DISA")
    data 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)

答案 2 :(得分:-2)

如果您使用val而不是var,也会发生这种情况。