{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/2594","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/2594/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/2594/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/2594/events","html_url":"https://github.com/realm/realm-java/issues/2594","id":147607073,"number":2594,"title":"Realm instance has already been closed.","user":{"login":"DanteAndroid","id":10005563,"avatar_url":"https://avatars.githubusercontent.com/u/10005563?v=3","gravatar_id":"","url":"https://api.github.com/users/DanteAndroid","html_url":"https://github.com/DanteAndroid","followers_url":"https://api.github.com/users/DanteAndroid/followers","following_url":"https://api.github.com/users/DanteAndroid/following{/other_user}","gists_url":"https://api.github.com/users/DanteAndroid/gists{/gist_id}","starred_url":"https://api.github.com/users/DanteAndroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanteAndroid/subscriptions","organizations_url":"https://api.github.com/users/DanteAndroid/orgs","repos_url":"https://api.github.com/users/DanteAndroid/repos","events_url":"https://api.github.com/users/DanteAndroid/events{/privacy}","received_events_url":"https://api.github.com/users/DanteAndroid/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-04-12T01:45:33Z","updated_at":"2016-04-19T07:52:44Z","closed_at":null,"body":"I received lots of Exception as the title says. But I can't locate where the problem is, although it seems to have something with a third banner library `convenientBanner`. \r\nI close Realm at `onDestory()` in `MainActivity` and other activities.\r\nTo find the problem, you may need to check out `BannerView`, `ZhihuListAdapter`(line 130) in my [repository](https://github.com/DanteAndroid/Knowledge).\r\nReally really appreciate it!\r\n\r\nLogcat:\r\n```\r\njava.lang.IllegalStateException: This Realm instance has already been closed, making it unusable.\r\n\tat io.realm.a.f(Unknown Source)\r\n\tat io.realm.al.b(Unknown Source)\r\n\tat io.realm.al.size(Unknown Source)\r\n\tat com.bigkoo.convenientbanner.a.a.a(Unknown Source)\r\n\tat com.bigkoo.convenientbanner.a.a.getCount(Unknown Source)\r\n\tat android.support.v4.view.ViewPager.setCurrentItemInternal(Unknown Source)\r\n\tat android.support.v4.view.ViewPager.setCurrentItemInternal(Unknown Source)\r\n\tat android.support.v4.view.ViewPager.setCurrentItem(Unknown Source)\r\n\tat com.bigkoo.convenientbanner.a.run(Unknown Source)\r\n\tat android.os.Handler.handleCallback(Handler.java:733)\r\n\tat android.os.Handler.dispatchMessage(Handler.java:95)\r\n\tat android.os.Looper.loop(Looper.java:136)\r\n\tat android.app.ActivityThread.main(ActivityThread.java:5016)\r\n\tat java.lang.reflect.Method.invokeNative(Native Method)\r\n\tat java.lang.reflect.Method.invoke(Method.java:515)\r\n\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)\r\n\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)\r\n\tat dalvik.system.NativeStart.main(Native Method)\r\n```"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/211780917","html_url":"https://github.com/realm/realm-java/issues/2594#issuecomment-211780917","issue_url":"https://api.github.com/repos/realm/realm-java/issues/2594","id":211780917,"user":{"login":"stk1m1","id":16395854,"avatar_url":"https://avatars.githubusercontent.com/u/16395854?v=3","gravatar_id":"","url":"https://api.github.com/users/stk1m1","html_url":"https://github.com/stk1m1","followers_url":"https://api.github.com/users/stk1m1/followers","following_url":"https://api.github.com/users/stk1m1/following{/other_user}","gists_url":"https://api.github.com/users/stk1m1/gists{/gist_id}","starred_url":"https://api.github.com/users/stk1m1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stk1m1/subscriptions","organizations_url":"https://api.github.com/users/stk1m1/orgs","repos_url":"https://api.github.com/users/stk1m1/repos","events_url":"https://api.github.com/users/stk1m1/events{/privacy}","received_events_url":"https://api.github.com/users/stk1m1/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T07:52:44Z","updated_at":"2016-04-19T07:52:44Z","body":"@DanteAndroid Could you please refactor according to @beeender 's suggestion and let us know how you've resolved your issue? \r\n\r\nI'd highly suggest to follow his suggestion since not only you keep an instance of realm in a static field but also re-assigning an instance of realm to _the very field_ in few more places in [`BaseActivity.java`](https://github.com/DanteAndroid/Knowledge/blob/9111f20c139f22fe45325fdb8cc0b127101d7aeb/app/src/main/java/com/dante/knowledge/ui/BaseActivity.java), which is inherited by other Acitivity classes in the same package. \r\n\r\nIn that way, there is a great chance that one realm could be referred from many Activities and that would lead to the crash you are experiencing."}}