R
R
Roman Svyatun2014-10-16 21:44:00
Java
Roman Svyatun, 2014-10-16 21:44:00

How to catch an IllegalStateException that is not being caught?

Dear habra community, here's a riddle for you. I've been solving for a few days now. I've never dealt with mobile development before, but damn it. Designed a database application. And the base is big, but that's okay. Everything was going well until I added too many fragments and everything fell into the abyss.
Introductory:
The application has several fragments with a ListView. They are filled from the database using a combination of SimpleCursorAdapter and Cursor Loader.
Let's take a look at the error log:

10-14 19:29:34.313  24409-24409/ru.endid.sqliteproject E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: ru.endid.sqliteproject, PID: 24409 
    java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT _id, name FROM company ORDER BY name 
            at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55) 
            at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58) 
            at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:152) 
            at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:124) 
            at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:214) 
            at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162) 
            at android.widget.CursorAdapter.getItemId(CursorAdapter.java:223) 
            at android.widget.AbsListView.onSaveInstanceState(AbsListView.java:1764) 
            at android.view.View.dispatchSaveInstanceState(View.java:12728) 
            at android.view.ViewGroup.dispatchFreezeSelfOnly(ViewGroup.java:2629) 
            at android.widget.AdapterView.dispatchSaveInstanceState(AdapterView.java:783) 
            at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2615) 
            at android.view.View.saveHierarchyState(View.java:12711) 
            at android.app.FragmentManagerImpl.saveFragmentViewState(FragmentManager.java:1577) 
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:951) 
            at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167) 
            at android.app.BackStackRecord.run(BackStackRecord.java:641) 
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 
            at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443) 
            at android.os.Handler.handleCallback(Handler.java:733) 
            at android.os.Handler.dispatchMessage(Handler.java:95) 
            at android.os.Looper.loop(Looper.java:136) 
            at android.app.ActivityThread.main(ActivityThread.java:5001) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) 
            at dalvik.system.NativeStart.main(Native Method)

As you can see, there is no reference to the place where the exception occurred in the code. Moreover, attempts to catch it with try - catch in suspicious places did not bring anything. First of all, these are the ContentProvider's methods for accessing the database. It is quite expected that the problem with this. But no! Loader'a methods were also checked - clean! In general, to whom it is interesting, I propose to search together.
PS Found the exact same bug on the Mozilla bugtracker here . It differs only in sql query. At least I'm not alone in my problem.
PPS I don't replace fragments, but use the add method when adding a new one. Then, when returning, I take the previous one from the BackStack. If you replace add with replace, the error disappears. So it's directly related to fragments and the cursor loader. But the error cannot be caught.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question