android - Room 不能选择一个构造函数,因为多个构造函数是合适的错误

标签 android constructor kotlin android-room android-components

我尝试在我的 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/

相关文章:

android - ACTION_SEND 附件未显示在 Instagram 中

android - 三星 Nexus S 与 HTC - NFC Intent Filter + AAR

android - 抽象 LCD 密度

java - javamail Authenticator 的构造函数如何工作?

c# - 如何克隆类实例?

android - 如何正确完成所有打开的 Activity ?

c++ - 为什么在使用大括号初始值设定项列表时首选 std::initializer_list 构造函数?

java - 在可绘制对象中使用 ?attr/color 时出现滑动错误

java - 如何使用ARCore识别盒子?

android - 使用 kotlin android 扩展在不同布局中引用具有相同 id 的 View