小编ajo*_*onk的帖子

房间持久性:实体和Pojos必须具有可用的公共构造函数

我正在尝试通过Room Persistence库将数据库添加到我的android应用中,并且出现此错误:

错误:实体和Pojos必须具有可用的公共构造函数。您可以有一个空的构造函数或一个其参数与字段匹配的构造函数(按名称和类型)。尝试了以下构造函数,但未能匹配:User(int,java.lang.String,java.lang.String,int,int,int,java.lang.String)-> [param:id->匹配字段:unmatched ,param:name->匹配字段:unmatched,param:gender->匹配字段:unmatched,param:age->匹配字段:unmatched,param:weight->匹配字段:unmatched,param:height->匹配字段:unmatched ,参数:锻炼->匹配字段:不匹配]

这是我的代码:

    @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;

} ...
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我做错了什么或错过了什么吗?

java database android

6
推荐指数
1
解决办法
3633
查看次数

标签 统计

android ×1

database ×1

java ×1