Hi I'm trying to use Room with Kotlin
in a MVP
based Project.
my problem is that when I create a data class and related DAO
all the classes would generated successfully but when a create the second data class and it's DAO
the Error:Cannot find setter for field.
thrown on rebuild command in 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)
I've also checked this link and this link but none of them worked for me
I finally found the solution. The problem is related to property naming.
The following causes errors at compile time:
@ColumnInfo(name = "IS_SOLVED") var isSolved
but when I changed the above to the following, the error is resolved:
@ColumnInfo(name = "IS_SOLVED") var solved
We cannot use SQLite reserved keywords line for field naming. I'm using Room version 1.0.0 and kotlin version 1.1.51.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With