1

Tout en utilisant la chambre android j'ai l'entité suivante:entité d'architecture de base de données Chambre étend erreur

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

Tout fonctionne très bien. Mais maintenant, je veux que mon POJO (Call.class) pour étend une classe abstraite comme suit:

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

Et je reçois l'erreur suivante:

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. 

Le parent (BaseViewTypeData.class) est une classe simple pour gérer plusieurs types de vue dans une vue recycleur.

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

} 

Répondre

3

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

Je pense que votre problème n'est pas BaseViewTypeData, mais avec BaseObservable, comme la chambre ne saura pas comment faire face à the BaseObservable fields. En général, il est peu probable que votre entité hérite de classes que vous ne contrôlez pas.

+0

Merci beaucoup! –