Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException: Couldn't read row 0, col 0 from CursorWindow (in GreenDAO's list method) #413

Open
di72nn opened this issue Jan 29, 2017 · 21 comments · Fixed by #874
Labels

Comments

@di72nn
Copy link
Member

di72nn commented Jan 29, 2017

From google play dev console:
Application version: 29.
Android version: Android 4.4.

java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
	at android.database.CursorWindow.nativeGetLong(Native Method)
	at android.database.CursorWindow.getLong(CursorWindow.java:507)
	at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
	at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220)
	at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
	at de.greenrobot.dao.AbstractDao.moveToNextUnlocked(AbstractDao.java:442)
	at de.greenrobot.dao.AbstractDao.loadAllUnlockOnWindowBounds(AbstractDao.java:422)
	at de.greenrobot.dao.AbstractDao.loadAllFromCursor(AbstractDao.java:401)
	at de.greenrobot.dao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:191)
	at de.greenrobot.dao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:21)
	at de.greenrobot.dao.query.Query.list(Query.java:77)
	at de.greenrobot.dao.query.QueryBuilder.list(QueryBuilder.java:388)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.getArticles(ArticlesListFragment.java:202)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.updateList(ArticlesListFragment.java:169)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.onResume(ArticlesListFragment.java:117)
	at android.support.v4.app.Fragment.performResume(Fragment.java:2133)
	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1156)
	at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:950)
	at android.support.v4.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManager.java:1319)
	at android.support.v4.app.FragmentManagerImpl.doPendingDeferredStart(FragmentManager.java:1705)
	at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1646)
	at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
	at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
	at android.support.v4.view.ViewPager.populate(ViewPager.java:1272)
	at android.support.v4.view.ViewPager.populate(ViewPager.java:1120)
	at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1646)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2566)
	at android.view.View.measure(View.java:16522)
	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
	at android.view.Choreographer.doCallbacks(Choreographer.java:574)
	at android.view.Choreographer.doFrame(Choreographer.java:544)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
	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:5158)
	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:796)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
	at dalvik.system.NativeStart.main(Native Method)
@di72nn
Copy link
Member Author

di72nn commented Jan 29, 2017

Seems to be the same as greenrobot/greenDAO#200.
Possible cause: too large content for SQLite cursor window: source.
Possible solution: store article content in files. Or maybe it's possible to work around it with OFFSET and LIMIT.

@di72nn
Copy link
Member Author

di72nn commented Apr 1, 2017

Two more reports.
Application version: 32.
Android version: Android 6.0.

java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
	at android.database.CursorWindow.nativeGetLong(Native Method)
	at android.database.CursorWindow.getLong(CursorWindow.java:524)
	at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
	at org.greenrobot.greendao.AbstractDao.loadCurrent(AbstractDao.java:541)
	at org.greenrobot.greendao.AbstractDao.loadAllUnlockOnWindowBounds(AbstractDao.java:498)
	at org.greenrobot.greendao.AbstractDao.loadAllFromCursor(AbstractDao.java:480)
	at org.greenrobot.greendao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:203)
	at org.greenrobot.greendao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:37)
	at org.greenrobot.greendao.query.Query.list(Query.java:89)
	at org.greenrobot.greendao.query.QueryBuilder.list(QueryBuilder.java:427)
	at fr.gaulupeau.apps.Poche.service.SecondaryService.fetchImages(SecondaryService.java:230)
	at fr.gaulupeau.apps.Poche.service.SecondaryService.onHandleIntent(SecondaryService.java:68)
	at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:158)
	at android.os.HandlerThread.run(HandlerThread.java:61)
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
	at android.database.CursorWindow.nativeGetLong(Native Method)
	at android.database.CursorWindow.getLong(CursorWindow.java:524)
	at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
	at org.greenrobot.greendao.AbstractDao.loadCurrent(AbstractDao.java:541)
	at org.greenrobot.greendao.AbstractDao.loadAllUnlockOnWindowBounds(AbstractDao.java:498)
	at org.greenrobot.greendao.AbstractDao.loadAllFromCursor(AbstractDao.java:480)
	at org.greenrobot.greendao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:203)
	at org.greenrobot.greendao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:37)
	at org.greenrobot.greendao.query.Query.list(Query.java:89)
	at org.greenrobot.greendao.query.QueryBuilder.list(QueryBuilder.java:427)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.getArticles(ArticlesListFragment.java:297)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.resetListContent(ArticlesListFragment.java:233)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.checkList(ArticlesListFragment.java:228)
	at fr.gaulupeau.apps.Poche.ui.ArticlesListFragment.onResume(ArticlesListFragment.java:146)
	at android.support.v4.app.Fragment.performResume(Fragment.java:2235)
	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1346)
	at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
	at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757)
	at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355)
	at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
	at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098)
	at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1979)
	at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
	at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
	at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
	at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
	at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3094)
	at android.view.View.measure(View.java:20195)
	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2646)
	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1601)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1893)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1489)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7472)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
	at android.view.Choreographer.doCallbacks(Choreographer.java:695)
	at android.view.Choreographer.doFrame(Choreographer.java:631)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:158)
	at android.app.ActivityThread.main(ActivityThread.java:7231)
	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)

@di72nn di72nn added the Bug label Apr 1, 2017
@di72nn
Copy link
Member Author

di72nn commented Apr 5, 2017

@di72nn
Copy link
Member Author

di72nn commented Apr 9, 2017

Application version: 32.
Android version: Android 6.0.

java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
	at android.database.CursorWindow.nativeGetLong(Native Method)
	at android.database.CursorWindow.getLong(CursorWindow.java:524)
	at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
	at org.greenrobot.greendao.AbstractDao.loadCurrent(AbstractDao.java:541)
	at org.greenrobot.greendao.AbstractDao.loadAllUnlockOnWindowBounds(AbstractDao.java:498)
	at org.greenrobot.greendao.AbstractDao.loadAllFromCursor(AbstractDao.java:480)
	at org.greenrobot.greendao.AbstractDao.loadAllAndCloseCursor(AbstractDao.java:203)
	at org.greenrobot.greendao.InternalQueryDaoAccess.loadAllAndCloseCursor(InternalQueryDaoAccess.java:37)
	at org.greenrobot.greendao.query.Query.list(Query.java:89)
	at org.greenrobot.greendao.query.QueryBuilder.list(QueryBuilder.java:427)
	at fr.gaulupeau.apps.Poche.network.FeedUpdater.updateInternal(FeedUpdater.java:149)
	at fr.gaulupeau.apps.Poche.network.FeedUpdater.update(FeedUpdater.java:110)
	at fr.gaulupeau.apps.Poche.service.MainService.updateFeed(MainService.java:352)
	at fr.gaulupeau.apps.Poche.service.MainService.onHandleIntent(MainService.java:88)
	at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:158)
	at android.os.HandlerThread.run(HandlerThread.java:61)

@di72nn di72nn changed the title IllegalStateException: Couldn't read row 0, col 0 from CursorWindow IllegalStateException: Couldn't read row 0, col 0 from CursorWindow (in GreenDAO's list method) Jun 27, 2017
@di72nn
Copy link
Member Author

di72nn commented Jun 27, 2017

Error reports like in #566 are still coming (from one user).

@Strubbl
Copy link
Contributor

Strubbl commented Jun 29, 2017

Maybe this size limit is a hint https://stackoverflow.com/a/21432966/709697 if greendao relies on android sqlite

@di72nn
Copy link
Member Author

di72nn commented Jun 29, 2017

Yup.

@Strubbl
Copy link
Contributor

Strubbl commented Jun 29, 2017

@di72nn
Copy link
Member Author

di72nn commented Jun 29, 2017

This shouldn't cause errors. It is highly unlikely that such an error exists in SQLite implementation Android uses (and nobody knows about it).

@Strubbl
Copy link
Contributor

Strubbl commented Jun 29, 2017

Yes, absolutely makes sense. Just tested it

06-29 21:16:47.761 5372-12636/fr.gaulupeau.apps.InThePoche.debug D/SecondaryService: fetchImages() total number: 3732
06-29 21:16:47.761 5372-12636/fr.gaulupeau.apps.InThePoche.debug D/SecondaryService: fetchImages() looping; offset: 0
...
06-29 21:17:55.498 5372-12636/fr.gaulupeau.apps.InThePoche.debug D/SecondaryService: fetchImages() looping; offset: 3750
06-29 21:17:55.525 5372-12636/fr.gaulupeau.apps.InThePoche.debug D/SecondaryService: fetchImages() no more articles
06-29 21:18:17.914 5372-12636/fr.gaulupeau.apps.InThePoche.debug D/SecondaryService: fetchImages() finished

@Strubbl
Copy link
Contributor

Strubbl commented Jun 29, 2017

Maybe reducing the query limit to 10 helps that particular user? (And does not hurt us.)

@di72nn
Copy link
Member Author

di72nn commented Jun 29, 2017

The error happens not only for images fetching. And we can't decrease values forever.
We should move article contents out of the SQLite DB into files. It would also provide some additional benefits like faster Article objects updates, some other queries should be faster I guess (I've not yet looked into it). It would take time to implement it, though.

@garrett-hopper
Copy link

What's the current status of this issue?
I'm running into the same issue with a large article collection (>1500).
Is there any sort of workaround?

@di72nn
Copy link
Member Author

di72nn commented Sep 13, 2017

I think the source of the problem is the size of specific articles (so they don't fit in the cursor window), not a total number of articles, but that's just a guess.
I'm not aware of any workaround.

Can you give some details about the time when the error happens? If it happens in the lists, does it happen in some specific (reproducible) moment?

I though about moving article content to file storage: one small DB with metadata and a bunch of files (one for each article). I haven't done any work on it yet.

@garrett-hopper
Copy link

I've just started using this.
When my pinboard import (of 1500 articles) was partially done (about 600), it was working.
However, now that it's finished importing everything, the unread tab crashes the app.
I've tried lots of different ways around this, but if my collection is syned locally and I move to the unread tab, it crashes with this error.

@di72nn
Copy link
Member Author

di72nn commented Sep 14, 2017

If you have time to experiment, you can try to add around 30 small articles and check whether the app fails to show the main screen (30 is the number of articles loaded in a list by default). However, the unread and favorite tabs may be loaded too (even if you didn't open them yet), so you may need to mark all these 30 articles as favorite and add another 30 archived articles.

If this will work, that would mean that it indeed breaks not because of the total number of articles.

@di72nn
Copy link
Member Author

di72nn commented Mar 8, 2018

@drakeet thanks for sharing your solution. I'll consider applying it as a temporary measure.

@guilhermesgb
Copy link

guilhermesgb commented Feb 14, 2019

What is @drakeet's solution? (Just out of curiosity.)

@di72nn
Copy link
Member Author

di72nn commented Nov 13, 2019

It was pretty much this code. However, be advised that this is a work-around, not a solution.

@Alkahirah
Copy link

I got the same issue that because of the cursor return row from the database with 2MB maximum
now try to make the size of image less than 2MB put the quality 0 in bitmap

@di72nn
Copy link
Member Author

di72nn commented Apr 1, 2021

Apparently IllegalStateException happens even for single articles *sigh*

Some experimenting needs to be done (to reproduce in dev environment).
Probably IllegalStateException also has to be caught in Article.getArticleContent().

@di72nn di72nn reopened this Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants