当前位置:网站首页>Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
2022-07-02 06:22:00 【原小明】
问题:
kotlin 更新值 1.2.6 版本时,room 表的实体类就编译不通过了,比如:
@Entity(tableName = "table_hex")
data class HexData constructor( @ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
@ColumnInfo(name = "code")
var code: String = "",
@ColumnInfo(name = "datas")
var datas: String = "") {
constructor() : this(0)
}
会出现下面警告和异常
Warning:(11, 2) 警告: There are multiple good constructors and Room will pick the no-arg construct
当新增加的字段时,就会编译失败,找不到 setter
方法,其实都是上面警告引起的
解决:
在构造函数上添加 Ignore
注解即可
@Entity(tableName = "table_hex")
data class HexData constructor( @ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
@ColumnInfo(name = "code")
var code: String = "",
@ColumnInfo(name = "datas")
var datas: String = "") {
@Ignore
constructor() : this(0)
}
边栏推荐
- 深入了解JUC并发(一)什么是JUC
- 【每日一题】写一个函数,判断一个字符串是否为另外一个字符串旋转之后的字符串。
- Idea announced a new default UI, which is too refreshing (including the application link)
- Log (common log framework)
- MySQL的10大經典錯誤
- 最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
- Common means of modeling: combination
- CUDA中的函数执行空间说明符
- Redis - cluster data distribution algorithm & hash slot
- CUDA中的存储空间修饰符
猜你喜欢
Data science [9]: SVD (2)
分布式事务 :可靠消息最终一致性方案
LeetCode 90. Subset II
VRRP之监视上行链路
New version of dedecms collection and release plug-in tutorial tool
Current situation analysis of Devops and noops
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
Redis——Cluster数据分布算法&哈希槽
sudo提权
找到页面当前元素z-index最高的数值
随机推荐
Introduce two automatic code generators to help improve work efficiency
BGP中的状态机
PgSQL学习笔记
CUDA与Direct3D 一致性
CUDA中的动态全局内存分配和操作
Redis——大Key問題
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
CUDA中的函数执行空间说明符
LeetCode 40. 组合总和 II
Invalid operation: Load into table ‘sources_orderdata‘ failed. Check ‘stl_load_errors‘ system table
实现strStr() II
MySQL的10大经典错误
TensorRT中的循环
CUDA用户对象
计算属性普通函数写法 和 set get 写法
代码技巧——Controller参数注解@RequestParam
CUDA中的线程层次
10 erreurs classiques de MySQL
eslint配置代码自动格式化
【每日一题】—华为机试01