错误:找不到字段的吸气剂;当Room使用数据类

时间:2018-07-01 08:53:12

标签: android kotlin android-room

我有这个数据类:

@Entity(tableName = User.TABLE_NAME)
data class User(
        @PrimaryKey @ColumnInfo(name = User.id) var id: String = "",
        @ColumnInfo(name = User.name) var name: String = "",
        @ColumnInfo(name = User.password) var password: String = "",
        @ColumnInfo(name = User.modDate) var modDate: DateTime = DateTime(1970, 1, 1, 0, 0)
)

在编译时出现以下错误:

e: C:\Users\Tibi\AndroidStudioProjects\Android_Sales\EventApp\app\build\tmp\kapt3\stubs\debug\com\tiborfarago\eventapp\database\User.java:11: error: Cannot find getter for field.
    private java.lang.String id$1;
                             ^
e: C:\Users\Tibi\AndroidStudioProjects\Android_Sales\EventApp\app\build\tmp\kapt3\stubs\debug\com\tiborfarago\eventapp\database\User.java:14: error: Cannot find getter for field.
    private java.lang.String name$1;
                             ^
e: C:\Users\Tibi\AndroidStudioProjects\Android_Sales\EventApp\app\build\tmp\kapt3\stubs\debug\com\tiborfarago\eventapp\database\User.java:17: error: Cannot find getter for field.
    private java.lang.String password$1;
                             ^
e: C:\Users\Tibi\AndroidStudioProjects\Android_Sales\EventApp\app\build\tmp\kapt3\stubs\debug\com\tiborfarago\eventapp\database\User.java:20: error: Cannot find getter for field.
    private org.joda.time.DateTime modDate$1;
                                   ^

如果我用Java重新创建该类,则该应用程序可以正常运行。

我不确定我应该提供什么其他信息,因为我像以前一样使用所有东西。

让我感到奇怪的是,它不会错过安装员,只会错过安装员。 编辑:现在,二传手也丢失了。

Edit2: 由于某些原因,这可行:

@Entity(tableName = "sfdfs")
data class Eventdasdsa(
        @PrimaryKey @ColumnInfo(name = "s") var idgfgh: String = "",
        @ColumnInfo(name = "sfdsfdfs") var locatgfhgfionId: String? = "",
        @ColumnInfo(name = "hhhhjghjg") var nafhfhgffme: String? = ""
)

1 个答案:

答案 0 :(得分:0)

我设法弄清楚了

在数据类的主体中,我有一个包含const vals的伴随对象。这些变量的名称与数据类的字段名称相同,这导致了问题。