【发布时间】:2019-05-21 07:44:19
【问题描述】:
我正在尝试通过 Room Persistence 库将数据库添加到我的 android 应用程序中,但出现此错误:
错误:实体和 Pojos 必须有一个可用的公共构造函数。您可以有一个空的构造函数或参数与字段匹配的构造函数(按名称和类型)。 尝试了以下构造函数,但它们未能匹配: User(int,java.lang.String,java.lang.String,int,int,int,java.lang.String) -> [param:id -> 匹配字段:不匹配,参数:名称 -> 匹配字段:不匹配,参数:性别 -> 匹配字段:不匹配,参数:年龄 -> 匹配字段:不匹配,参数:体重 -> 匹配字段:不匹配,参数:高度 -> 匹配字段:不匹配,参数:锻炼 -> 匹配字段:不匹配]
这是我的代码:
@Entity
public class User {
@PrimaryKey
private int userId;
private String userName;
private String userGender;
private int userAge;
private int userWeight;
private int userHeight;
private String workoutPlan;
public User(int id, String name, String gender, int age, int weight, int height, String workout) {
this.userId = id;
this.userName = name;
this.userGender = gender;
this.userAge = age;
this.userWeight = weight;
this.userHeight = height;
this.workoutPlan = workout;
} ...
谁能告诉我我做错了什么或我错过了什么?
【问题讨论】: