ORMLite dataType=DataType.SERIALIZABLE doesn't

2019-07-14 18:54发布

I have declared my type to be SERIALIZABLE as specified by ORMLite documentation, but I still get:

ORMLite can't store unknown class interface java.io.Serializable for field 'task_titles'. Serializable fields must specify dataType=DataType.SERIALIZABLE

My code looks like this:

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

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

I also tried using since ArrayList is serializable but without luck.

private ArrayList<String> task_titles; 

For other reasons (limitations in applications outside my control), it is not a good option in this case to create another table containing the task titles. Here's the full exception:

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条回答
ゆ 、 Hurt°
2楼-- · 2019-07-14 19:31

ORMLite can't store unknown class interface java.io.Serializable for field 'sort_order_of_lists'. Serializable fields must specify dataType=DataType.SERIALIZABLE

Am I missing something? This error is talking about the field sort_order_of_lists but you are showing another field:

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

I suspect that the sort_order_of_lists is missing the dataType=DataType.SERIALIZABLE annotation field. Is that field in a base class?

If that is not the problem then I suspect you are using the table-config feature for Android and you need to re-generate the table-config because it is out of sync with your objects. See the link for more details on this feature:

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

查看更多
登录 后发表回答