ORMLite dataType = DataType.SERIALIZABLE不起作用

时间:2013-02-13 20:21:27

标签: java android serialization ormlite

我已经按照ORMLite文档的规定将我的类型声明为SERIALIZABLE,但我仍然得到:

  

ORMLite无法为字段'task_titles'存储未知的类接口java.io.Serializable。可序列化字段必须指定dataType = DataType.SERIALIZABLE

我的代码如下所示:

@DatabaseField(dataType=DataType.SERIALIZABLE) 
private Serializable task_titles;

public User() {
    task_titles = new ArrayList<String>();
}

我也尝试使用,因为ArrayList是可序列化的,但没有运气。

private ArrayList<String> task_titles; 

由于其他原因(我控制之外的应用程序的限制),在这种情况下创建包含任务标题的另一个表不是一个好的选择。这是完整的例外:

02-13 21:07:12.593: E/AndroidRuntime(15500): java.lang.RuntimeException: Unable to start activity ComponentInfo{lemonhat.snote/lemonhat.snote.MainActivity}: java.lang.RuntimeException: Could not create RuntimeExcepitionDao for class class lemonhat.snote.db.User
02-13 21:07:12.593: E/AndroidRuntime(15500):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
...
02-13 21:07:12.593: E/AndroidRuntime(15500): Caused by: java.lang.RuntimeException: Could not create RuntimeExcepitionDao for class class lemonhat.snote.db.User
02-13 21:07:12.593: E/AndroidRuntime(15500):    at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getRuntimeExceptionDao(OrmLiteSqliteOpenHelper.java:260)
02-13 21:07:12.593: E/AndroidRuntime(15500):    at lemonhat.snote.db.DatabaseHelper.getUserDataDao(DatabaseHelper.java:109)
02-13 21:07:12.593: E/AndroidRuntime(15500):    at lemonhat.snote.MainActivity.onCreate(MainActivity.java:80)
...
02-13 21:07:12.593: E/AndroidRuntime(15500): Caused by: java.sql.SQLException: ORMLite can't store unknown class interface java.io.Serializable for field 'sort_order_of_lists'. Serializable fields must specify dataType=DataType.SERIALIZABLE
02-13 21:07:12.593: E/AndroidRuntime(15500):    at com.j256.ormlite.field.FieldType.<init>(FieldType.java:183)
02-13 21:07:12.593: E/AndroidRuntime(15500):    at com.j256.ormlite.table.DatabaseTableConfig.convertFieldConfigs(DatabaseTableConfig.java:236)
02-13 21:07:12.593: E/AndroidRuntime(15500):    at com.j256.ormlite.table.DatabaseTableConfig.extractFieldTypes(DatabaseTableConfig.java:101)
02-13 21:07:12.593: E/AndroidRuntime(15500):    at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:151)
...

1 个答案:

答案 0 :(得分:2)

  

ORMLite无法为字段'sort_order_of_lists'存储未知的类接口java.io.Serializable。可序列化字段必须指定dataType = DataType.SERIALIZABLE

我错过了什么吗?此错误是在讨论字段sort_order_of_lists,但您正在显示另一个字段:

@DatabaseField(dataType=DataType.SERIALIZABLE) 
private Serializable task_titles;

我怀疑sort_order_of_lists缺少dataType=DataType.SERIALIZABLE注释字段。该字段是否在基类中?

如果那不是问题,那么我怀疑你正在使用Android的table-config功能,你需要重新生成table-config,因为它与你的对象不同步。有关此功能的详细信息,请参阅链接:

  

http://ormlite.com/docs/table-config