【发布时间】:2020-10-31 10:37:41
【问题描述】:
这似乎是一个非常常见的错误,因为我能够找到与此类似的其他问题,但无法确定问题出在哪里。
所以我有这个实体
@Entity(tableName = "story_id")
data class StoryIdEntity(
@PrimaryKey
@ColumnInfo(name = "type")
val type: String,
@ColumnInfo(name = "ids")
val ids: List<Int>
)
我有这个 Dao 接口
@Dao
interface HackerNewsDaoInterface {
@Query("SELECT ids FROM story_id where type = :type")
suspend fun getStories(type: String): List<Int>
}
当我编译这个时,我收到以下错误。
- 实体和 POJO 必须具有可用的公共构造函数。您可以有一个空的构造函数或一个参数与字段匹配的构造函数(按名称和类型)。
- 查询返回一些列 [ids],这些列没有被 java.lang.Integer 使用。您可以在字段上使用 @ColumnInfo 注释来指定映射。您可以通过使用 @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) 注释方法来抑制此警告。查询返回的列:ids。 java.lang.Integer 中的字段:
B/w 我有一个功能正常的 List 类型转换器。
更新 1
我暂时把Dao的方法改了,让它生效。
@Dao
interface HackerNewsDaoInterface {
@Query("SELECT * FROM story_id where type = :type")
suspend fun getStories(type: String): StoryIdEntity
}
【问题讨论】:
标签: android kotlin android-room