我在我的Android應用程序的sqlite3的數據庫上運行。我剛從預先填充的數據庫中讀取了200k行和14列。參賽作品是文字。所有列的數據類型都是文本。查詢最多11個字母(例如ABANDONMENT)的文字效果很好。但是對於12個或更多(例如,ABANDONMENTS),該應用程序崩潰。這裏是logcat的:無法分配CursorWindow
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)
代碼:
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();
}
那麼,是什麼錯誤意味着以及爲什麼應用程序崩潰?
完整的代碼會有幫助。你是否在自己管理它之後關閉了光標,爲什麼不簡單地調用cursor.moveToNext()而不是!cursor.isAfterLast() –
完整的應用程序代碼是1000行。 cursor.isAfterLast用於檢查光標是否已經遍歷所有結果,如果有,我可以停止。 –
你正在關閉while循環內的遊標嗎? –