3

我正在使用 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--
#################################
4

1 回答 1

1
java.lang.IllegalArgumentException: Field FieldType:name=activity,
    class=Relation_Participants is a primitive class
    class com.lordcardrecorder.model.CardActivity but marked as foreign

因此,出于某种原因, ORMLite认为您的Relation_Participants类是原始类型。我怀疑问题是您的 Androidormlite_config.txt文件中缓存了字段和类型信息的无效信息。我会立即删除此文件,然后重新运行您的程序以查看它是否有效。如果没有,那么您需要重新生成它。

如果问题仍然存在,请发布ormlite_config.txt列出字段的文件部分Relation_Participants。是不是说它是原始的?

于 2013-07-30T21:57:41.427 回答