Pergunta

I'm using ormlite-core-4.46 and ormlite-android-4.46, and I'm still getting this error. below is my exception trace log:

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

and this is the class which has the foreign collection:

@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;

this is the class which has the foreign field to the above class:

@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;

Anybody knows that the problem is??? It's really driving me crazy!!


I assume the android config.txt as the ormlite_config.txt, So I delete the file, and generate the file again, but the problem still persists. Below is the file:

#
# 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--
#################################
Foi útil?

Solução

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

So for some reason ORMLite thinks that your Relation_Participants class is a primitive type. I suspect that the problem is invalid information inside of your Android ormlite_config.txt file which caches the field and type information. I would immediately remove this file and then re-run your program to see if it works. If it doesn't then you need to regenerate it.

If the problem still happens then please post the section of the ormlite_config.txt file that lists the Relation_Participants fieldd. Is it saying it is a primitive?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top