Kotlin:实体和pojo必须有一个可用的公共构造函数。您可以有一个空的构造函数或一个其参数与字段(按名称和类型)匹配的构造函数。
1、修改前的写法(报错了):
@Entity(tableName = "inspectItem")
data class InspectItemInfo(
@PrimaryKey
@ColumnInfo(name = "id")
@NonNull
var carInspectRecordId: Int,
var cubeName: String,
@Ignore
var imageType: String,
var plateColor: String,
var plateNo: String,
var shotTime: String,
var storagePath: String,
var bottomImageUrl: String
)
报错信息:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
2、修改后的(写法一):
说明:提供空构造方法。
@Entity(tableName = "inspectItem")
data class InspectItemInfo(
@PrimaryKey
@ColumnInfo(name = "id")
@NonNull
var carInspectRecordId: Int,
var cubeName: String,
@Ignore
var imageType: String,
var plateColor: String,
var plateNo: String,
var shotTime: String,
var storagePath: String,
var bottomImageUrl: String
) {
constructor() : this(0, "", "", "", "", "", "", "")
}
3、修改后的(写法二):
说明:ignore的属性需要给默认值。
@Entity(tableName = "inspectItem")
data class InspectItemInfo(
@PrimaryKey
@ColumnInfo(name = "id")
@NonNull
var carInspectRecordId: Int,
var cubeName: String,
var plateColor: String,
var plateNo: String,
var shotTime: String,
var storagePath: String,
var bottomImageUrl: String
) {
@Ignore
var imageType: String = ""
}