5

我正在尝试将类对象的数组列表保存到 ormlite 数据库中,但它给出了错误 java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class java.util.ArrayList

我的代码是

@DatabaseTable
public class ManageModelDetails {

@DatabaseField(generatedId = true)
private int id;

@DatabaseField(foreign = true, foreignAutoRefresh = true)
private ArrayList<ModelDetails> listModelDetails;

// ===============================================
public ManageModelDetails() {
    super();
}

// ===============================================

public ManageModelDetails(int id, ArrayList<ModelDetails> listModelDetails) {
    super();
    this.id = id;
    this.listModelDetails = listModelDetails;
}

// ===============================================

public void setId(int id) {
    this.id = id;
}

public int getId() {
    return id;
}

public void setModelList(ArrayList<ModelDetails> listModelDetails) {
    this.listModelDetails = listModelDetails;
}

public ArrayList<ModelDetails> getModelList() {
    return listModelDetails;
}

}
4

2 回答 2

6

我认为您需要使用外国收藏。看看这里:

于 2013-08-26T19:05:23.097 回答
4

如果要将对象的 ArrayList 保存到 ORMLite,最简单的方法是:

@DatabaseField(dataType = DataType.SERIALIZABLE)
private SerializedList<MyObject> myObjects;

并获取我的对象列表:

public List<MyObject> getMyObjects() {
  return myObjects;
}

这是序列化列表:

public class SerializedList<E> extends ArrayList<E> implements Serializable {
}
于 2015-07-23T21:57:25.953 回答