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 }
然后在第3行(根据日志),我时不时地遇到此异常(以下摘录):
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)
...
任何想法为什么会引发此异常?谢谢!
最佳答案
我怀疑该错误可能与您一直没有正确关闭游标有关。尝试:
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
}
游标应始终处于关闭状态(无论其是否为空)。确保您的应用程序的其余部分也正在执行此操作。
关于android - 无法通过活页夹创建光标窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14316082/