【问题标题】:Room database architecture entity extends error房间数据库架构实体扩展错误
【发布时间】:2017-07-25 10:20:11
【问题描述】:

在使用 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;
}

一切都很好。但现在我希望我的 pojo (Call.class) 扩展一个抽象类,如下所示:

@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) 是一个简单的类,用于处理回收器视图中的多种视图类型。

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

}

【问题讨论】:

    标签: android android-database android-room android-architecture-components


    【解决方案1】:

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

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

    一般来说,让您的实体从您无法控制的类继承是不太可能的。

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多