Room database architecture entity extends error

风流意气都作罢 提交于 2019-12-23 22:06:00

问题


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

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 {
....
....
}

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.

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

}

回答1:


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

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.



来源:https://stackoverflow.com/questions/45300414/room-database-architecture-entity-extends-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!