IllegalArgumentException:字段xxx是基本类类xxx,但标记为外部

时间:2013-07-30 01:04:41

标签: android ormlite foreign-collection

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

1 个答案:

答案 0 :(得分: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类是原始类型。我怀疑问题是Android ormlite_config.txt文件中的无效信息,它会缓存字段和类型信息。我会立即删除此文件,然后重新运行您的程序,看它是否有效。如果它没有,那么你需要重新生成它。

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