有沒有from
或to
方法來從數據庫中選擇數據領域,當我嘗試使用between()
,我得到一個不必要的項目在結果的結尾,所以我想刪除它後得到它複製到新的listObject
。UnsupportedOperationException當刪除RealmResult的副本
但即使在複製它在另一個列表對象後,我無法刪除realmResult
中的最後一項。
RealmResults<CalendarDto> currentMonthDTOList = Realm.getDefaultInstance().where(CalendarDto.class).between("primaryDayId", startingDayPrimaryKey, endingDayPrimaryKey).findAll().sort("primaryDayId", Sort.ASCENDING);
List<CalendarDto> currentList = currentMonthDTOList;
currentList.remove(currentList.size());
但我得到的錯誤說unsupportedOperationException。
我的日誌貓看起來像這樣
FATAL EXCEPTION: main
Process: com.toyanathpatro.gurkha, PID: 17714
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.toyanathpatro.gurkha/com.toyanathpatro.gurkha.activities.DashBoardActivity}: java.lang.ClassCastException: io.realm.RealmResults cannot be cast to java.util.ArrayList
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: io.realm.RealmResults cannot be cast to java.util.ArrayList
at com.toyanathpatro.gurkha.fragments.GridCalendarFragment.fetchData(GridCalendarFragment.java:84)
at com.toyanathpatro.gurkha.fragments.GridCalendarFragment.onCreateView(GridCalendarFragment.java:42)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
at android.app.Activity.performStart(Activity.java:6253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
謝謝你這麼多:) – erluxman