在ormlite Android的使用DataType.SERIALIZABLE对象的存储目录 [英] Storing List of objects using DataType.SERIALIZABLE in ormlite android

查看:2054
本文介绍了在ormlite Android的使用DataType.SERIALIZABLE对象的存储目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存在Android的使用ORMlite我的模型如下一个ArrayList

How to save an ArrayList using ORMlite in android my model is as follows

class Model{
    @DatabaseField
    public String type = "";

    @DatabaseField
    public String name = "";

    @DatabaseField
    public Date dateTime = null;

    @DatabaseField
    ArrayList<Item> items = null;
}

和项目类有

class Item{
     @DatabaseField
     String itemName;
     ...
}

我收到以下异常:

I am getting the following exception :

java.sql.SQLException: ORMLite can't store unknown class class
      java.util.ArrayList for field 'items'.   Serializable fields must specify
      dataType=DataType.SERIALIZABLE

但是,当我指定我的字段

But when i specify my field as

@DatabaseField(dataType = DataType.SERIALIZABLE)
ArrayList<Item> items = null;

编译器提供了一个名为场误差不能得到解决,请帮助我。

The compiler gives a error called field cannot be resolved please help me with this.

推荐答案

我刚刚换了错误消息是:

I've just changed the error message to be:

ORMLite不知道如何存储类
        java.util.ArrayList的现场项目。使用另一个类,定制的持留,或序列化使用它的dataType = DataType.SERIALIZABLE

ORMLite does not know how to store class java.util.ArrayList for field 'items'. Use another class, custom persister, or to serialize it use dataType=DataType.SERIALIZABLE

也许更有意义? ORMLite 是想说,它不知道如何存储列表中的一个字段。如果要存放物品的集合,那么也许你应该看看在国外收集文档

Maybe that makes more sense? ORMLite is trying to say that it doesn't know how to store lists in a field. If you want to store collection of items then maybe you should take a look at the foreign-collection documentation.

这篇关于在ormlite Android的使用DataType.SERIALIZABLE对象的存储目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆