android 多界面光标,android.database.CursorWindowAllocationException:光标窗口分配2048 kb失败,即使关闭游标...
關(guān)于CursorWindowAllocatoinException有很多關(guān)于SO的問(wèn)題:
他們都建議游標(biāo)在使用后必須關(guān)閉.但這并沒(méi)有解決我的問(wèn)題.這是我的代碼:
String query = "select serial from tbl1 union select serial from tbl2 union select serial from tbl3";
SQLiteDatabase db = null;
Cursor cur = null;
try {
SettingsDatabaseHelper dal = new SettingsDatabaseHelper(
c);
db = dal.getReadableDatabase();
cur = db.rawQuery(query, null);
int numRows = cur.getCount();
if (numRows > 0) {
cur.moveToFirst();
int serialIdx = cur.getColumnIndexOrThrow("serial");
for (boolean hasItem = cur.moveToFirst(); hasItem; hasItem = cur
.moveToNext()) {
String serial = cur.getString(serialIdx);
if (Validator.getInstance().isValidSerial(serial))
serials.add(serial);
}
}
} finally {
if (cur != null)
cur.close();
if (db != null)
db.close();
}
我每隔幾秒鐘運(yùn)行一次這個(gè)方法.半小時(shí)后,我在int numRows = cur.getCount()中得到CursorWindowAllocationException;然后我的服務(wù)停止.
由于我關(guān)閉游標(biāo),所以我的Helper類(lèi)可能有問(wèn)題.這是代碼:
public class SettingsDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "mydb.db";
private static final int DATABASE_VERSION = 1;
private static final String TBL_CREATE="create table...";
public SettingsDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(TBL_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onCreate(db);
}
}
如何防止這個(gè)異常被拋出?
總結(jié)
以上是生活随笔為你收集整理的android 多界面光标,android.database.CursorWindowAllocationException:光标窗口分配2048 kb失败,即使关闭游标...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 一篇文章彻底搞懂snowflake算法及
- 下一篇: android自定义水波纹,androi