Java android.database.CursorWindowAllocationException:2048 kb的光标窗口分配失败打开游标=971(#此进程打开的游标=971)

Java android.database.CursorWindowAllocationException:2048 kb的光标窗口分配失败打开游标=971(#此进程打开的游标=971),java,android,database,multithreading,sqlite,Java,Android,Database,Multithreading,Sqlite,android.database.CursorWindowAllocationException:2048 kb的光标窗口分配失败。#打开游标=971(#此进程打开的游标=971) 嗨,我有一个查询数据库的控制器。用于异步获取数据的代码,因为我有1000多条记录 public void query(final Uri contentUri, final String where, final String[] selecti

android.database.CursorWindowAllocationException:2048 kb的光标窗口分配失败。#打开游标=971(#此进程打开的游标=971)

嗨,我有一个查询数据库的控制器。用于异步获取数据的代码,因为我有1000多条记录

public void query(final Uri contentUri,
                  final String where,
                  final String[] selectionArgs,
                  final String sortOrder,
                  final int from,
                  final int limit,
                  final AdvancedQueryListener<Cursor> listener) {
    if (listener == null)
        return;
    if (null == SamsungApp.getAppContext())
        return;
    final ContentResolver mContentResolver = SamsungApp.getAppContext().getContentResolver();
    final Handler mHandler = Utility.instantiateHandler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case 1:
                    Cursor cursor = (Cursor) message.obj;
                    listener.onGetResult(cursor);
            }
            return false;
        }
    });

    Runnable queryRunner = new Runnable() {
        @Override
        public void run() {
            StringBuilder sqlStatement = null;

            if (!TextUtils.isEmpty(sortOrder)) {
                if (sqlStatement == null)
                    sqlStatement = new StringBuilder();
                sqlStatement.append(sortOrder);
            }

            if (limit > 0) {
                if (sqlStatement == null)
                    sqlStatement = new StringBuilder();
                sqlStatement.append(" LIMIT ");
                sqlStatement.append(limit);
            }

            if (from > 0) {
                if (sqlStatement == null)
                    sqlStatement = new StringBuilder();
                sqlStatement.append(" OFFSET ");
                sqlStatement.append(from);
            }
            Cursor cursor = mContentResolver.query(contentUri, null, where, selectionArgs, sqlStatement.toString());
            Message message = mHandler.obtainMessage(1);
            message.obj = cursor;
            mHandler.sendMessage(message);
        }
    };

    FixedThreadPoolExecutor.execute(queryRunner);
}
下面给出了我的内容提供商

我的问题是,每次我都会遇到问题

注意 每个人都告诉我关闭光标
cursor.close()
like

在我的申请表中的每一处,我都加入了

try{
    //code 
}finally{
    if(null!=cursor)
        cursor.close
}
帮我找出问题所在


提前感谢

关闭
光标
handleMessage
光标上的处理在另一个管理器中。如果在此处关闭,则会产生太多问题。因此,请在任何位置关闭它-基本上,如果您有太多打开的游标,请在侦听器方法(
listener.onGetResult
)中关闭游标不是一个好主意,是吗?关闭光标是否有帮助?关闭
光标
内的
handleMessage
光标上的处理在另一个管理器中。如果在此处关闭,则会产生太多问题。因此,请在任何位置关闭它-基本上,如果您有太多打开的游标,请在侦听器方法(
listener.onGetResult
)中关闭游标不是一个好主意,是吗?关闭光标有帮助吗?
public boolean close() {
    if (this.isActive) {
        mAppDbHelper.removeConnection();
    }
    int count = mAppDbHelper.getCounter();
    if (count == 0) {
        synchronized (mutex) {
            if (mSqldb.inTransaction()) mSqldb.endTransaction();
            if (mSqldb.isOpen()) mSqldb.close();
            mSqldb = null;
        }
    }
    return (count == 0);
}


public SQLiteDatabase open() {
    if (!this.isActive) {
        mAppDbHelper.addConnection();
    }
    if (mSqldb == null || !mSqldb.isOpen()) {
        synchronized (mutex) {
            mSqldb = mAppDbHelper.getWritableDatabase();
        }
    }
    this.isActive = true;
    return mSqldb;
}

// 
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    final SQLiteDatabase db = open();
    Cursor cursor = null;
    if (db != null) {
        /* SQLiteQueryBuilder helps to construct queries that are more complex than
         * those supported by the SQLiteDatabase functions (for example, sub queries).
         */
        SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
        queryBuilder.setTables(uri.getLastPathSegment()); // Extract table name fromDeviceCursor uri
        cursor = queryBuilder.query(db,
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder
        );
        if (cursor != null) {
            cursor.setNotificationUri(getContext().getContentResolver(), uri);
        }
    } else {
        throw new DataLayerException(DEBUG_TAG + "SQLiteDatabase is null");
    }
    return cursor;
}
FATAL EXCEPTION: main
                                 Process: com.samsung.lighting, PID: 4949
                                 android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)
                                     at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
                                     at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:843)
                                     at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
                                     at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
                                     at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
                                     at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
                                     at android.content.ContentResolver.query(ContentResolver.java:512)
                                     at android.content.ContentResolver.query(ContentResolver.java:435)
                                     at com.samsung.lighting.storage.repository.impl.WiSeGalleryRepositaryImpl.getNonSyncedIcon(WiSeGalleryRepositaryImpl.java:278)
                                     at com.samsung.lighting.sync.OfflineSyncManager.syncAddedIcons(OfflineSyncManager.java:194)
                                     at com.samsung.lighting.sync.OfflineSyncManager.startSyncing(OfflineSyncManager.java:164)
                                     at com.samsung.lighting.sync.OfflineSyncManager.onFailure(OfflineSyncManager.java:737)
                                     at com.wise.cloud.group.WiSeCloudGroupManager$9.onFailure(WiSeCloudGroupManager.java:1603)
                                     at com.wise.cloud.queue.WiSeQueueManagement.addToQueue(WiSeQueueManagement.java:173)
                                     at com.wise.cloud.queue.WiSeQueueManagement.initialCheckInToQueueManagement(WiSeQueueManagement.java:117)
                                     at com.wise.cloud.group.WiSeCloudGroupManager.setLogicalGroupAssociations(WiSeCloudGroupManager.java:1662)
                                     at com.samsung.lighting.cloud_interactor.CloudGroupManager.setGroupAssociations(CloudGroupManager.java:131)
                                     at com.samsung.lighting.sync.OfflineSyncManager$7.onGetResult(OfflineSyncManager.java:391)
                                     at com.samsung.lighting.sync.OfflineSyncManager$7.onGetResult(OfflineSyncManager.java:387)
                                     at com.samsung.lighting.storage.repository.impl.WiSeGroupAssociationRepositoryImpl$1.onGetResult(WiSeGroupAssociationRepositoryImpl.java:344)
                                     at com.samsung.lighting.storage.repository.impl.WiSeGroupAssociationRepositoryImpl$1.onGetResult(WiSeGroupAssociationRepositoryImpl.java:330)
                                     at com.samsung.lighting.storage.repository.SamsungContentResolver$1.handleMessage(SamsungContentResolver.java:73)
                                     at android.os.Handler.dispatchMessage(Handler.java:98)
                                     at android.os.Looper.loop(Looper.java:148)
                                     at android.app.ActivityThread.main(ActivityThread.java:5451)
                                     at java.lang.reflect.Method.invoke(Native Method)
                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
try{
    //code 
}finally{
    if(null!=cursor)
        cursor.close
}