我已将我的类型声明SERIALIZABLE
为 ORMLite 文档中指定的类型,但我仍然得到:
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)
...