日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 多界面光标,android.database.CursorWindowAllocationException:光标窗口分配2048 kb失败,即使关闭游标...

發布時間:2023/12/19 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 多界面光标,android.database.CursorWindowAllocationException:光标窗口分配2048 kb失败,即使关闭游标... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

關于CursorWindowAllocatoinException有很多關于SO的問題:

他們都建議游標在使用后必須關閉.但這并沒有解決我的問題.這是我的代碼:

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();

}

我每隔幾秒鐘運行一次這個方法.半小時后,我在int numRows = cur.getCount()中得到CursorWindowAllocationException;然后我的服務停止.

由于我關閉游標,所以我的Helper類可能有問題.這是代碼:

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);

}

}

如何防止這個異常被拋出?

總結

以上是生活随笔為你收集整理的android 多界面光标,android.database.CursorWindowAllocationException:光标窗口分配2048 kb失败,即使关闭游标...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。