会议室数据库体系结构实体扩展错误 [英] Room database architecture entity extends error

查看:80
本文介绍了会议室数据库体系结构实体扩展错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用android Room时,我具有以下实体:

While using android Room i'm having the following entity:

@Entity
public class Call implements Parcelable {

@PrimaryKey(autoGenerate = true)
private long id;
private String filePath;
private long durationInMillis;
private String phoneNumber;
private int isStarred;
private int isIncoming;
private long timestampCreated;
}

一切正常.但是现在我希望我的pojo(Call.class)扩展一个Abstract类,如下所示:

All works great. But now I want my pojo (Call.class) to extends an Abstract class as following:

@Entity
public class Call extends BaseViewTypeData implements Parcelable {
....
....
}

我收到以下错误:

Error:Cannot figure out how to save this field into database. You can 
consider adding a type converter for it.
Error:Cannot find getter for field.
Error:Cannot find setter for field.
Error:Cannot figure out how to read this field from a cursor.
Error:Cannot find getter for field.
Error:Cannot find setter for field.

父级(BaseViewTypeData.class)是一个简单的类,用于处理回收器视图中的多种视图类型.

The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views.

public abstract class BaseViewTypeData extends BaseObservable {

public static final int VIEW_TYPE_CALL = 0;
public static final int VIEW_TYPE_SETTINGS_HEADER = 1;
public static final int VIEW_TYPE_SETTINGS_TITLE_SUBTITLE = 2;
public static final int VIEW_TYPE_SETTINGS_TITLE_SUBTITLE_SWITCH = 3;
public static final int VIEW_TYPE_SETTINGS_DIVIDER = 4;
public static final int VIEW_TYPE_SETTINGS_TITLE_SWITCH = 5;
public static final int VIEW_TYPE_CALL_LOG_DATA = 6;
public static final int VIEW_TYPE_CHECKBOX_TITLE_SUBTITLE = 7;

@Ignore
public abstract int getViewType();

}

推荐答案

父级(BaseViewTypeData.class)是一个简单的类,用于处理回收器视图中的多种视图类型.

The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views.

我怀疑您的问题不是BaseViewTypeData,而是BaseObservable,因为Room不知道如何处理

I suspect that your problem is not with BaseViewTypeData, but with BaseObservable, as Room will not know how to deal with the BaseObservable fields.

通常,让您的实体从您无法控制的类继承是不可能的.

In general, having your entity inherit from classes that you do not control is unlikely to work.

这篇关于会议室数据库体系结构实体扩展错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆