Cursor window could not be created from binder

末鹿安然 提交于 2019-11-29 16:40:01

问题


1 Cursor cursor = contentResolver.query(MY_URI, new String[] { "first" }, null, null, null);
2 if (cursor != null) {
3   if (cursor.moveToFirst()) {
4       first = cursor.getString(cursor.getColumnIndex("first"));
5       cursor.close();
6   }
7 }

Then on line #3 (according to the logs), I every now and then I come across this exception (excerpt below):

android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
    at android.database.CursorWindow.<init>(CursorWindow.java:134)
    at android.database.CursorWindow.<init>(CursorWindow.java:41)
    at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:709)
    at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:707)
    at android.database.CursorWindow.newFromParcel(CursorWindow.java:718)
    at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:196)

...

Any ideas why it is throwing this exception? Thanks!


回答1:


I suspect the error may be related to you not closing your cursors properly all the time. Try:

Cursor cursor = contentResolver.query(MY_URI, new String[] { "first" }, null, null, null);
if (cursor != null) {
  if (cursor.moveToFirst()) {
      first = cursor.getString(cursor.getColumnIndex("first"));
  }
  cursor.close(); ///// Changed here
}

The cursor should always be closed (regardless of whether or not its empty). Make sure the rest of your app is doing this as well.




回答2:


Try another thread

new Thread(new Runnable(){ public void run(){

...here all code

}});

. But by Android SDK source codes look like 4.0.2_r1

130  private CursorWindow(Parcel source) {
131 mStartPos = source.readInt();
132 mWindowPtr = nativeCreateFromParcel(source);
133 if (mWindowPtr == 0) {
134 throw new CursorWindowAllocationException("Cursor window could not be "
135 + "created from binder.");
136 }
137 mName = nativeGetName(mWindowPtr);
138 mCloseGuard.open("close");
139 }
where mWIndowPtr is Int


回答3:


Try out this way:

 if (cursor != null) {
  cursor.moveToFirst();
   do {
   first = cursor.getString(cursor.getColumnIndex("first"));
  }while(cursor.moveToNext());

}



来源:https://stackoverflow.com/questions/14316082/cursor-window-could-not-be-created-from-binder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!