无法分配CursorWindow [英] Could not allocate CursorWindow

查看:1373
本文介绍了无法分配CursorWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序操作上的的SQLite3 的数据库。我刚刚从pre填充的数据库有20万行和14列的读取。参赛作品不过是空话。所有列的数据类型是文本。了查询词,以11个字母(如:遗弃)工作正​​常。但为12或更大(例如ABANDONMENTS),应用程序崩溃。这里是logcat的:

I'm operating on an SQLite3 database in my android app. I just read from the pre populated database that has 200k rows and 14 columns. Entries are words. Datatype of all columns is text. Querying for words up to 11 letters (eg. ABANDONMENT) works fine. But for 12 or greater (eg. ABANDONMENTS), the app crashes. Here is the logcat:

Could not allocate CursorWindow '//data//data//com.example.myapp//databases//database.sqlite' of size 2097152 due to error -12.
threadid=11: thread exiting with uncaught exception (group=0x40adf9f0)
FATAL EXCEPTION: Thread-2883
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=861 (# cursors opened by this proc=861)
at android.database.CursorWindow.<init>(CursorWindow.java:104)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:162)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:161)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201)
at com.example.myapp.MainActivity.query(MainActivity.java:815)
at com.example.myapp.MainActivity$2.run(MainActivity.java:356)
at java.lang.Thread.run(Thread.java:856)

code:

code:

query = "select * from words where col_1 = \"" + (myWord)+ "\";";
cursor = database.rawQuery(query, null);
if (cursor != null)                                          
    cursor.moveToFirst(); // line 815
if (!cursor.isAfterLast()) {
    do {
        for (i = 1; i < cursor.getColumnCount(); i++) {
            temp = cursor.getString(i);
            //other stuff
        }
    } while (cursor.moveToNext());
    cursor.close();
}

那么,是什么错误的意思,为什么是应用程序崩溃?

So what does the error mean and why is the app crashing?

推荐答案

我quering在一个循环。而关闭游标内循环,而不是外面解决了这个问题。

I was quering in a loop. And closing the cursor inside the loop and not outside solved the problem.

这篇关于无法分配CursorWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆