How to store the arraylist in ormlite database

前端 未结 2 1515
天命终不由人
天命终不由人 2020-12-10 18:47

I am trying to save the arraylist of class objects into the ormlite database , but it is giving the error , java.lang.IllegalArgumentException: No fields have a DatabaseFiel

2条回答
  •  無奈伤痛
    2020-12-10 19:13

    If you want to save an ArrayList of objects to ORMLite the easiest way is this:

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

    and to get my list of objects:

    public List getMyObjects() {
      return myObjects;
    }
    

    and here is SerializedList:

    public class SerializedList extends ArrayList implements Serializable {
    }
    

提交回复
热议问题