我有以下型号:
@Entity(foreignKeys = @ForeignKey(
entity = ClassModel.class,
childColumns = "classModelId",
parentColumns = "id",
onDelete = ForeignKey.CASCADE)
)
public class _0 {
@PrimaryKey(autoGenerate = true)
private long id;
private long classModelId;
@SerializedName("userinfo")
@Expose
private Userinfo userinfo;
@SerializedName("enrolls")
@Expose
private List<Enroll> enrolls = null;
// --- CONSTRUCTORS ---
@Ignore
public _0(){
}
public _0(long id, long classModelId, Userinfo userinfo, List<Enroll> enrolls) {
this.id = id;
this.classModelId = classModelId;
this.userinfo = userinfo;
this.enrolls = enrolls;
}
// --- GETTER ---
public long getId() {
return id;
}
public long getClassModelId() {
return classModelId;
}
public List<Enroll> getEnrolls() {
return enrolls;
}
public Userinfo getUserinfo() {
return userinfo;
}
// --- SETTER ---
public void setEnrolls(List<Enroll> enrolls) {
this.enrolls = enrolls;
}
public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}
public void setId(long id) {
this.id = id;
}
public void setClassModelId(long classModelId) {
this.classModelId = classModelId;
}
}
然后告诉我这个错误:error:无法找出如何将此字段保存到数据库中。可以考虑为它添加一个类型转换器:<代码>波纹线:
@SerializedName("userinfo")
@Expose
private Userinfo userinfo;
@SerializedName("enrolls")
@Expose
private List<Enroll> enrolls = null;
而
Userinfo
就像下面这样:
@Entity(foreignKeys = @ForeignKey(
entity = _0.class,
childColumns = "_0Id",
parentColumns = "id",
onDelete = ForeignKey.CASCADE)
)
public class Userinfo {
@PrimaryKey(autoGenerate = true)
private long id;
private long _0Id;
@SerializedName("userid")
@Expose
private String userid;
@SerializedName("eduid")
@Expose
private String eduid;
@SerializedName("cnt")
@Expose
private Integer cnt;
// --- CONSTRUCTORS ---
public Userinfo(){
}
public Userinfo(long id, long _0Id, String userid, String eduid, Integer cnt) {
this.id = id;
this._0Id = _0Id;
this.userid = userid;
this.eduid = eduid;
this.cnt = cnt;
}
// --- GETTER ---
public String getUserid() {
return userid;
}
public long getId() {
return id;
}
public long get_0Id() {
return _0Id;
}
public String getEduid() {
return eduid;
}
public Integer getCnt() {
return cnt;
}
// --- SETTER ---
public void setId(long id) {
this.id = id;
}
public void set_0Id(long _0Id) {
this._0Id = _0Id;
}
public void setUserid(String userid) {
this.userid = userid;
}
public void setEduid(String eduid) {
this.eduid = eduid;
}
public void setCnt(Integer cnt) {
this.cnt = cnt;
}
}
和
列表
@Entity(foreignKeys = @ForeignKey(
entity = _0.class,
childColumns = "_0Id",
parentColumns = "id",
onDelete = ForeignKey.CASCADE)
)
public class Enroll {
private long _0Id;
@SerializedName("username")
@Expose
private String username;
@PrimaryKey
@SerializedName("id")
@Expose
private String id;
@SerializedName("course_id")
@Expose
private String courseId;
@SerializedName("course_name")
@Expose
private String courseName;
@SerializedName("category_id")
@Expose
private String categoryId;
@SerializedName("category_name")
@Expose
private String categoryName;
@SerializedName("teacher")
@Expose
private List<Teacher> teacher = null;
@SerializedName("is_teacher")
@Expose
private Integer isTeacher;
@SerializedName("course_info")
@Expose
private CourseInfo courseInfo;
@SerializedName("assign")
@Expose
private Assign assign;
@SerializedName("quiz")
@Expose
private Quiz quiz;
@SerializedName("adobeconnect")
@Expose
private Adobeconnect adobeconnect;
// --- CONSTRUCTORS ---
public Enroll() {
}
public Enroll(long _0Id,
String username,
String id,
String courseId,
String courseName,
String categoryId,
String categoryName,
List<Teacher> teacher,
Integer isTeacher,
CourseInfo courseInfo,
Assign assign,
Quiz quiz,
Adobeconnect adobeconnect) {
this._0Id = _0Id;
this.username = username;
this.id = id;
this.courseId = courseId;
this.courseName = courseName;
this.categoryId = categoryId;
this.categoryName = categoryName;
this.teacher = teacher;
this.isTeacher = isTeacher;
this.courseInfo = courseInfo;
this.assign = assign;
this.quiz = quiz;
this.adobeconnect = adobeconnect;
}
// --- GETTER ---
public long get_0Id() {
return _0Id;
}
public String getUsername() {
return username;
}
public String getId() {
return id;
}
public String getCourseId() {
return courseId;
}
public String getCourseName() {
return courseName;
}
public String getCategoryId() {
return categoryId;
}
public String getCategoryName() {
return categoryName;
}
public List<Teacher> getTeacher() {
return teacher;
}
public Integer getIsTeacher() {
return isTeacher;
}
public CourseInfo getCourseInfo() {
return courseInfo;
}
public Assign getAssign() {
return assign;
}
public Quiz getQuiz() {
return quiz;
}
public Adobeconnect getAdobeconnect() {
return adobeconnect;
}
// --- SETTER ---
public void set_0Id(long _0Id) {
this._0Id = _0Id;
}
public void setUsername(String username) {
this.username = username;
}
public void setId(String id) {
this.id = id;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public void setTeacher(List<Teacher> teacher) {
this.teacher = teacher;
}
public void setIsTeacher(Integer isTeacher) {
this.isTeacher = isTeacher;
}
public void setCourseInfo(CourseInfo courseInfo) {
this.courseInfo = courseInfo;
}
public void setAssign(Assign assign) {
this.assign = assign;
}
public void setQuiz(Quiz quiz) {
this.quiz = quiz;
}
public void setAdobeconnect(Adobeconnect adobeconnect) {
this.adobeconnect = adobeconnect;
}
}
文件室不支持直接存储列表的功能,您需要添加类型转换器来实现这一点。创建一个TypeConverter,如下所示
public class MyCustomTypeConverter {
Gson gson = new Gson();
@TypeConverter
public static List<Enroll> stringToSomeObjectList(String data) {
if (data == null) {
return Collections.emptyList();
}
Type listType = new TypeToken<List<Enroll>>() {}.getType();
return gson.fromJson(data, listType);
}
@TypeConverter
public static String someObjectListToString(List<Enroll> someObjects) {
return gson.toJson(someObjects);
}
}
并在实体类中注释字段,如下所示
@TypeConverters(MyCustomTypeConverter.class)
public final List<Enroll> someObjects;
所以,当我试图编译它时,我得到了这个错误: 我不熟悉房间实施,所以我不知道如何解决这个问题。
当我试图在TaskClass中创建一个实体时,它说它无法将优先级类型保存到数据库中,我遇到了这个错误。Priority是我用几个常量变量创建的枚举类。 我的错误 我搞不清楚到底是什么问题。旁注:我正在看一个android开发课程,我只是跟着指导老师,但他做的同样的事情是给我一个错误,我怎么能修复这个问题? 我的优先枚举类 我的任务课 我的项目等级文件 我的模块GRADLE文件
文件CrimetypeConverters.kt 错误:错误:无法确定如何将此字段保存到数据库中。可以考虑为其添加一个类型转换器。private java.util.date日期;C:\users\asus\AndroidStudioProjects\CriminalIntentV2\app\build\tmp\kapt3\stubs\debug\com\bignerdranch\android\
我要用作的数据类如下: My details对象是一个名为的自定义类的列表,其中包含: 此列表中只有一项。正如上面的数据类中提到的,我还为实体中的特定字段指定了一个TypeConzer类。其定义如下: 为了完成我的问题,下面是我的实现: 采用这种方法,我在构建应用程序时会出现以下错误: 甚至我也怀疑出了问题,因为我的IDE没有显示任何地方都可以使用的中的函数。像这样: 我知道很多人过去也在Stac
我正在开发新闻应用程序,我遇到以下错误:无法确定如何将此字段保存到数据库中。可以考虑为其添加类型转换器。私人决赛约德戈贝克。科米洛夫。穆索巴卡扬吉利克里。模型Source=null; 在我的SportNews数据库下面。我在其中实现数据库的kt类 下面是SportNewsDao。kt 下面是文章。kt S以下ource.kt 下面SourceTypeConverters.kt我试图进行转换的地方
当我想将我的JSON记录到房间数据库中时,我遇到了一个问题。 我的数据类是: )