一秒查询2次数据库 , 爆出 android.database.CursorWindowAllocationException : Cursor Window alloction of 2048 kb failed.
查询代码:
public static List<HeadInfo> queryHeadInfoByOrder(Context context, String order) {
SQLiteDatabase db = DBHelper.getSQLiteDb(context);
List<HeadInfo> list = new ArrayList<HeadInfo>();
String sql = “select * from head_info “;
// 查询数据
Cursor cursor = db.rawQuery(sql, null);
try {
while (cursor.moveToNext()) {
HeadInfo info = new HeadInfo();
info.setId(cursor.getString(cursor.getColumnIndex(“id”)));
info.setLink(cursor.getString(cursor.getColumnIndex(“link”)));
info.setLocationLink(cursor.getString(cursor.getColumnIndex(“locationLink”)));
info.setMediatype(cursor.getString(cursor.getColumnIndex(“mediatype”)));
info.setOrder(cursor.getString(cursor.getColumnIndex(“sortorder”)));
info.setStatus(cursor.getString(cursor.getColumnIndex(“status”)));
list.add(info);
}
} finally {
if(cursor != null)
cursor.close();
if(db != null)
db.close();
}
return list;
}
查询代码:
public static List<HeadInfo> queryHeadInfoByOrder(Context context, String order) {
SQLiteDatabase db = DBHelper.getSQLiteDb(context);
List<HeadInfo> list = new ArrayList<HeadInfo>();
String sql = “select * from head_info “;
// 查询数据
Cursor cursor = db.rawQuery(sql, null);
try {
while (cursor.moveToNext()) {
HeadInfo info = new HeadInfo();
info.setId(cursor.getString(cursor.getColumnIndex(“id”)));
info.setLink(cursor.getString(cursor.getColumnIndex(“link”)));
info.setLocationLink(cursor.getString(cursor.getColumnIndex(“locationLink”)));
info.setMediatype(cursor.getString(cursor.getColumnIndex(“mediatype”)));
info.setOrder(cursor.getString(cursor.getColumnIndex(“sortorder”)));
info.setStatus(cursor.getString(cursor.getColumnIndex(“status”)));
list.add(info);
}
} finally {
if(cursor != null)
cursor.close();
if(db != null)
db.close();
}
return list;
}
解决方案
40
先查询表的数据量,假如过大,做分批处理 你这个是数据条数很多吗?