public class WorkoutBlock implements Parcelable{
@DatabaseField(generatedId = true, allowGeneratedIdInsert = true, columnName = "workout_block_id")
private Long id;
/*Field I am trying to add to*/
@ForeignCollectionField(columnName = "exercises")
private ForeignCollection<WorkoutExercise> exercises = null;
@ForeignCollectionField
private ForeignCollection<Rest> rests;
public void addComponent(WorkoutComponent component){
if(exercises == null) {
try {
Dao<WorkoutExercise,Long> dao = DatabaseHelper.getStaticWexDao();
exercises = dao.getEmptyForeignCollection("exercises");
} catch (SQLException e) {
e.printStackTrace();
}
}
if(component instanceof WorkoutExercise){
exercises.add((WorkoutExercise) component);
}else if(component instanceof Rest){
rests.add((Rest) component);
}
}
У меня есть следующий код.Я пытаюсь инициализировать «упражнения» ForeignCollection
методом getEmptyForeignCollection()
перед добавлением к нему элементов, но он продолжает выдавать IllegalArgumentException
, говоря:
Не удалось найти поле с именем упражнения
когда я вызываю метод.Это не работает, когда я удаляю атрибут columnName
.Что я делаю неправильно?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.codecool.nopainnogain, PID: 12521
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codecool.nopainnogain/com.codecool.nopainnogain.MainActivity}: java.lang.IllegalArgumentException: Could not find a field named exercises
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalArgumentException: Could not find a field named exercises
at com.j256.ormlite.dao.BaseDaoImpl.makeEmptyForeignCollection(BaseDaoImpl.java:1086)
at com.j256.ormlite.dao.BaseDaoImpl.getEmptyForeignCollection(BaseDaoImpl.java:824)
at com.codecool.nopainnogain.model.WorkoutBlock.addComponent(WorkoutBlock.java:36)
at com.codecool.nopainnogain.dataaccess.InMemoryDataAccess.populateData(InMemoryDataAccess.java:87)
at com.codecool.nopainnogain.dataaccess.InMemoryDataAccess.<init>(InMemoryDataAccess.java:20)
at com.codecool.nopainnogain.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)