简体   繁体   English

会议室数据库架构实体扩展错误

[英]Room database architecture entity extends error

While using android Room i'm having the following entity: 使用android Room时,我具有以下实体:

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

All works great. 一切都很好。 But now I want my pojo (Call.class) to extends an Abstract class as following: 但是现在我希望我的pojo(Call.class)扩展一个Abstract类,如下所示:

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

And i'm getting the following error: 而且我收到以下错误:

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.

The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views. 父类(BaseViewTypeData.class)是一个简单的类,用于处理回收器视图中的多种视图类型。

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();

}

The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views. 父类(BaseViewTypeData.class)是一个简单的类,用于处理回收器视图中的多种视图类型。

I suspect that your problem is not with BaseViewTypeData , but with BaseObservable , as Room will not know how to deal with the BaseObservable fields . 我怀疑您的问题不是与BaseViewTypeData ,而是与BaseObservable ,因为Room不知道如何处理BaseObservable字段

In general, having your entity inherit from classes that you do not control is unlikely to work. 通常,让实体继承您无法控制的类是不太可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM