06-09 10:18:57.033 6129-6129/com.seguehealth.community.debug E/null﹕ Illegal state exception trying to get item count.
java.lang.IllegalStateException: Illegal State: Table is closed, and no longer valid to operate on.
at io.realm.internal.TableView.nativeSize(Native Method)
at io.realm.internal.TableView.size(TableView.java:129)
at io.realm.RealmResults.size(RealmResults.java:305)
at io.realm.RealmBaseAdapter.getCount(RealmBaseAdapter.java:65)
at com.myapp.MyAdapter.getItemCount(MyAdapter.java:58)
at android.support.v7.widget.RecyclerView$LayoutManager.getRowCountForAccessibility(RecyclerView.java:7469)
at android.support.v7.widget.RecyclerView$LayoutManager.onInitializeAccessibilityNodeInfo(RecyclerView.java:7344)
at android.support.v7.widget.RecyclerView$LayoutManager.onInitializeAccessibilityNodeInfo(RecyclerView.java:7304)
at android.support.v7.widget.RecyclerViewAccessibilityDelegate.onInitializeAccessibilityNodeInfo(RecyclerViewAccessibilityDelegate.java:59)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.onInitializeAccessibilityNodeInfo(AccessibilityDelegateCompat.java:233)
at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.onInitializeAccessibilityNodeInfo(AccessibilityDelegateCompatJellyBean.java:61)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:5525)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:5488)
at android.view.View$AccessibilityDelegate.createAccessibilityNodeInfo(View.java:20854)
at android.view.View.createAccessibilityNodeInfo(View.java:5473)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:1064)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:888)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:155)
at android.view.AccessibilityInteractionController.access$400(AccessibilityInteractionController.java:53)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1236)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
@Override
public int getItemCount() {
try {
if (getRealmAdapter() != null) {
return getRealmAdapter().getCount();
}
}
catch (IllegalStateException ise) {
// I know the realm is closed here, it gets reset in onResume.
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/2c700e7e-530c-487a-a757-80f71da9568e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The realm life cycle is tied to the activity life cycle for both activities. The first thing done in OnCreate (after super.OnCreate()) is to get an instance, the last thing done in onDestroy is to close it. In fact they both extend the same base activity class that handles this for them.
When two activities are involved (master activity and detail activity) with fragments (master fragment, detail fragment), with a recyclerview in the master fragment, and adapter configured as per the URL (the fragment gets the realm from the activity), the crash occurs when rapidly cycling between activities.
The id value from the selected item in master view is passed to the detail activity. The detail fragment gets the realm from the activity, and looks up the item to populate the UI.
Fragments do not have retainInstance set.
I would expect getReamAdapter() to be null.
I will try and replicate outside my codebase, and send you the code that exercises this.
I've already gone ahead and moved to a single monolithic activity to work around this.