我正在使用 ormlite-core-4.46 和 ormlite-android-4.46,但我仍然收到此错误。以下是我的异常跟踪日志:
07-29 22:41:07.539: E/AndroidRuntime(1249): at java.lang.Thread.run(Thread.java:856)
07-29 22:41:07.539: E/AndroidRuntime(1249): Caused by: java.lang.IllegalArgumentException: Field FieldType:name=activity,class=Relation_Participants is a primitive class class com.lordcardrecorder.model.CardActivity but marked as foreign
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:323)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:200)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:126)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:117)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.BaseDaoImpl$5.<init>(BaseDaoImpl.java:909)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:909)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.DaoManager.doCreateDao(DaoManager.java:359)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.DaoManager.createDaoFromConfig(DaoManager.java:326)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:55)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:218)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:53)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.lordcardrecorder.support.DatabaseHelper.onCreate(DatabaseHelper.java:56)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.onCreate(OrmLiteSqliteOpenHelper.java:207)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.commonsware.cwac.loaderex.acl.SQLiteCursorLoader.buildCursor(SQLiteCursorLoader.java:54)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.commonsware.cwac.loaderex.acl.AbstractCursorLoader.loadInBackground(AbstractCursorLoader.java:38)
07-29 22:41:07.539: E/AndroidRuntime(1249): at com.commonsware.cwac.loaderex.acl.AbstractCursorLoader.loadInBackground(AbstractCursorLoader.java:1)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:240)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
07-29 22:41:07.539: E/AndroidRuntime(1249): at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
07-29 22:41:07.539: E/AndroidRuntime(1249): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-29 22:41:07.539: E/AndroidRuntime(1249): ... 3 more
这是具有外部集合的类:
@DatabaseTable(tableName = "activity")
public class CardActivity {
@DatabaseField(generatedId = true)
private int _id;
@DatabaseField
private String name;
@DatabaseField
private Date start;
@DatabaseField
private Date end;
@ForeignCollectionField(eager = false)
private ForeignCollection<Relation_Participants> participants;
这是具有上述类的外部字段的类:
@DatabaseTable(tableName = "relation_participants")
public class Relation_Participants {
@DatabaseField(generatedId = true)
private int _id;
@DatabaseField(foreign = true)
private CardActivity activity;
@DatabaseField(foreign = true)
private Player player;
有谁知道问题出在哪里???真的让我快疯了!!
我假设android config.txt 为ormlite_config.txt,所以我删除了该文件,并再次生成该文件,但问题仍然存在。下面是文件:
#
# generated on 2013/07/31 08:49:58
#
# --table-start--
dataClass=com.lordcardrecorder.model.CardActivity
tableName=activity
# --table-fields-start--
# --field-start--
fieldName=_id
generatedId=true
# --field-end--
# --field-start--
fieldName=name
# --field-end--
# --field-start--
fieldName=start
# --field-end--
# --field-start--
fieldName=end
# --field-end--
# --field-start--
fieldName=participants
foreignCollection=true
# --field-end--
# --table-fields-end--
# --table-end--
#################################
# --table-start--
dataClass=com.lordcardrecorder.model.Player
tableName=player
# --table-fields-start--
# --field-start--
fieldName=_id
generatedId=true
# --field-end--
# --field-start--
fieldName=name
# --field-end--
# --field-start--
fieldName=deactive
# --field-end--
# --field-start--
fieldName=sex
# --field-end--
# --table-fields-end--
# --table-end--
#################################
# --table-start--
dataClass=com.lordcardrecorder.model.Relation_Participants
tableName=relation_participants
# --table-fields-start--
# --field-start--
fieldName=_id
generatedId=true
# --field-end--
# --field-start--
fieldName=activity
foreign=true
# --field-end--
# --field-start--
fieldName=player
foreign=true
# --field-end--
# --table-fields-end--
# --table-end--
#################################