首页 > 解决方案 > android.database.CursorWindowAllocationException: 512000 kb 的光标窗口分配失败:: 某些 android 设备中的问题

问题描述

当运行应用程序某些 android 设备时,它会显示错误

android.database.CursorWindowAllocationException: Cursor window allocation of 512000 kb failed. # Open Cursors=1 (# cursors opened by this proc=1)
    at android.database.CursorWindow.<init>(CursorWindow.java:108)
    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:140)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:134)
    at com.material.components.database.tables.Tbl_BookList.getBookList(Tbl_BookList.java:110)
    at com.material.components.fragment.FragmentHome$1.onResponse(FragmentHome.java:64)
    at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)

读取 getMybookList() 函数时会出现问题。代码是

public List<BookList> getMyBookList() {

        SQLiteDatabase db = DbHelper.getInstance().getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from " + TABLE_BOOK_LIST+ " where " + COL_BOOK_LIST_read + " = 1" , null);
        List<BookList> callPriorityList = new ArrayList<>(cursor.getCount());
        cursor.moveToFirst();
        for (int i = 0; i < cursor.getCount(); cursor.moveToNext(), i++) {
            BookList bookList = new BookList();
            bookList.setId(cursor.getInt(cursor.getColumnIndex(COL_BOOK_LIST_id)));
            bookList.setBook_title(cursor.getString(cursor.getColumnIndex(COL_BOOK_LIST_title)));
            bookList.setBook_auther(cursor.getString(cursor.getColumnIndex(COL_BOOK_LIST_author)));
            bookList.setCover_image(cursor.getString(cursor.getColumnIndex(COL_BOOK_LIST_cover)));
            bookList.setBanner_image(cursor.getString(cursor.getColumnIndex(COL_BOOK_LIST_banner)));
            bookList.setBook_description(cursor.getString(cursor.getColumnIndex(COL_BOOK_LIST_discription)));
            callPriorityList.add(bookList);

        }
        cursor.close();

        return callPriorityList;
    }

标签: androidsqliteandroid-cursor

解决方案


推荐阅读