【问题标题】:Error while implementing Room实施 Room 时出错
【发布时间】:2018-12-12 20:16:20
【问题描述】:

错误:

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).  

我的实体是

@Entity
data class Category(var category: String) {

@field: PrimaryKey(autoGenerate = true)
var categoryId: Int = 0


}

【问题讨论】:

  • 发布您的模型类以供参考。
  • 错误说明了问题所在。添加一个空的构造函数(例如:public Dog(){}

标签: android mvvm android-room


【解决方案1】:

根据错误信息,您需要为该类添加构造函数。

@Entity data class Category(var category: String) {

@field: PrimaryKey(autoGenerate = true) var categoryId: Int = 0

constructor() : this(0) 

}

【讨论】:

    猜你喜欢
    • 2018-06-07
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多