本文介绍了房间持久性:实体和Pojos必须具有可用的公共构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过Room Persistence库将数据库添加到我的android应用中,并且出现此错误:
I am trying to add a database to my android app through the Room Persistence library and i am getting this error:
这是我的代码:
@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;
} ...
有人可以告诉我我在做什么错误或我错过了什么?
Can someone please tell me what i am doing wrong or what i missed?
推荐答案
请更改参数名称,使其与实体属性匹配。
Please change names of the parameters such that it matches entity attributes.
public User(int userId, String userName, String userGender, int userAge, int userWeight, int userHeight, String workoutPlan) {
this.userId = userId;
this.userName = userName;
this.userGender = userGender;
this.userAge = userAge;
this.userWeight = userWeight;
this.userHeight = userHeight;
this.workoutPlan = workoutPlan;
} ...
为了保持持久性,它在Room中使用JavaBeans约定。有关更多信息:
For persistance, it uses JavaBeans conventions in Room. For more information:https://developer.android.com/training/data-storage/room/defining-data#java
这篇关于房间持久性:实体和Pojos必须具有可用的公共构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!