我正在将一个项目转换为 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/
相关文章:
generics - 如何在 Kotlin 中获取泛型参数类
kotlin - 使用 Gradle 和 Kotlin 构建自执行 JAR
kotlin - 警告 : API 'variant.getPackageLibrary()' is
java - Kotlin:使用 lambda 代替函数式接口(interface)?
java - 如何在 Kotlin 中组合 Intent 标志
android-studio - Kotlin:为什么 Android Studio 中的大多数变量
android - 如何将 Kotlin 与 Proguard 一起使用