作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在将一个项目转换为 Kotlin,并且我正在尝试使我的模型(也是我的实体)成为一个数据类我打算使用 Moshi 转换来自 API 的 JSON 响应
@Entity(tableName = "movies")
data class MovieKt(
@PrimaryKey
var id : Int,
var title: String,
var overview: String,
var poster_path: String,
var backdrop_path: String,
var release_date: String,
var vote_average: Double,
var isFavorite: Int
)
由于以下错误,我无法构建应用程序
Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). Cannot find setter for field.
我找到的例子离this不远了
关于如何解决的想法?
最佳答案
在您的情况下这不是问题,但对于其他人来说,如果您的主构造函数中有 @Ignore 参数,则可能会发生此错误,即 Room 期望有:
例如:
@Entity(tableName = "movies")
data class MovieKt(
@PrimaryKey
var id : Int,
var title: String,
@Ignore var overview: String)
不会工作。这将:
@Entity(tableName = "movies")
data class MovieKt(
@PrimaryKey
var id : Int,
var title: String)
关于android - 房间持久性 : Error:Entities and Pojos must have a usable public constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44485631/
我是一名优秀的程序员,十分优秀!