gpt4 book ai didi

android - 房间数据库架构实体扩展错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:45:28 24 4
gpt4 key购买 nike

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

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,而在于BaseObservable,因为Room 不知道如何处理the BaseObservable fields。 .

一般来说,让您的实体继承不受您控制的类不太可能奏效。

关于android - 房间数据库架构实体扩展错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45300414/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com