Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Room Kotlin Cannot find setter for field

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

like image 968
alireza rahmaty Avatar asked Mar 07 '23 21:03

alireza rahmaty


1 Answers

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.

like image 162
alireza rahmaty Avatar answered Mar 10 '23 11:03

alireza rahmaty