我尝试在我的 android kotlin 项目中实现持久库,但在编译时发现此错误:
error: Room cannot pick a constructor since multiple constructors are suitable. Try to annotate unwanted constructors with @Ignore.
错误代码:
@Entity
data class Site(
var name: String = "",
var url: String = "",
@PrimaryKey(autoGenerate = true) var id: Long = 0)
最佳答案
我有这个错误是因为 Kotlin 显然为具有默认参数值的单个 Kotlin 构造函数生成了多个 Java 构造函数。工作代码见下:
@Entity
data class Site(
var name: String,
var url: String,
@PrimaryKey(autoGenerate = true) var id: Long)
关于android - Room 不能选择一个构造函数,因为多个构造函数是合适的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44620835/