lundi 12 janvier 2015

SQLite Android Leaked

I've this method to read the database:


class BDUtilities



public BDUtilities(Context context){
this.context = context;
this.bd = new BDHelper(context);
this.db_reader = bd.getReadableDatabase();
this.db_writer = bd.getWritableDatabase();
}

public ArrayList<Boolean> getPreferences() {
ArrayList<Boolean> resultados = new ArrayList<Boolean>();
if (checkBeforeUse()) {
try {
int user_id = getUserId();

Cursor c = db_reader.rawQuery("select cb_save_login, cb_save_pic_after_share," +
"cb_upload_anonym, cb_init_cat_pref, user_id from prefs where user_id = ?", new String[] { String.valueOf(user_id) });

if (c.getCount() > 0){
c.moveToFirst();
resultados.add(parse(c.getString(c.getColumnIndex("cb_save_login"))));
resultados.add(parse(c.getString(c.getColumnIndex("cb_save_pic_after_share"))));
resultados.add(parse(c.getString(c.getColumnIndex("cb_upload_anonym"))));
resultados.add(parse(c.getString(c.getColumnIndex("cb_init_cat_pref"))));
c.close();
} else { c.close(); }
}
finally {
//both error
//bd.close();
//db_reader.close(); //error:
//01-12 06:05:36.370: E/AndroidRuntime(1681): java.lang.IllegalStateException:
//attempt to re-open an already-closed object: SQLiteDatabase:
//data/data/com.example.photopt/databases/projeto_ddm.db
}
}
return resultados;
}


I've tried to close db_reader that has bd_reader = database.getReadableDatabase(); but has error.


This code: This doesn't return error but after some uses it shows this:



01-12 05:51:29.647: W/SQLiteConnectionPool(1762): A SQLiteConnection object for database '/data/data/com.example.photopt/databases/projeto_ddm.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.



Aucun commentaire:

Enregistrer un commentaire