报错信息:
android.database.sqlite.SQLiteCantOpenDatabaseException:
unable to open database file (Sqlite code 14), (OS error - 24:Too many open files)
DatabaseHelper dbHelper = new DatabaseHelper(this, "zhishidianData", null, 1);
final SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from zhishidian where pid = 0", null);
if (cursor != null && cursor.getCount() > 0) {
nianjiList.clear();
while (cursor.moveToNext()) {//游标是否继续向下移动
//操作
}
}
原因:
db 和 cursor 使用后,没有调用close方法,多次调用后报错。
解决方法:
调用 cursor.close() db.close()
DatabaseHelper dbHelper = new DatabaseHelper(this, "zhishidianData", null, 1);
final SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from zhishidian where pid = 0", null);
if (cursor != null && cursor.getCount() > 0) {
nianjiList.clear();
while (cursor.moveToNext()) {//游标是否继续向下移动
//操作
}
}
cursor.close();
db.close();