Android- SQLite created and never closed
I have a problem. I Worked with one table in my database and I had no problem...
Well now I add another table and problems started..
In my principal activity, I open the database (writable mode) to fill information stored in an array.. then I close it, after that I reopen it (readable mode) and I fill a table with data stored in my database... then I close DB. that was working in all the activities I was doing that..
Well now I have another activity that just do the same with another table, open it as writable to fill it, close.. and then open it as readable and fill a table and close..
And after I do this, I have the LogCat that says SQLite created and never closed.. what? I did the same thing as always.. here is part of my activity which is getting me into trouble:
UsuariosSQLiteHelper usdbh =
new UsuariosSQLiteHelper(this, "DBIncidentes", null, 1);
SQLiteDatabase db = usdbh.getWritableDatabase(); //Abro base de datos para escritura
if(db != null)
{
db.execSQL("DELETE from Moviles");
for (int i=0; i<= (vecTotal.length) -1; i++) {
String reg = vecTotal[i].toString();
String [] inc = TextUtils.split(reg, "\\^");
String numMovil = inc[0];
String colMovil = inc[1];
String estado = inc[2];
String localidad = inc[3];
String strCantServ = inc[4];
Integer cantServ = Integer.parseInt(strCantServ);
try{
//Insertamos los datos en la tabla Incidentes
db.execSQL("INSERT INTO Moviles ( idInterno, numMovil, colMovil, estado, localidad, cantServ) " +
"VALUES ("+(i+1)+", '" + numMovil +"', '" + colMovil +"' , '" + estado +"', '" + localidad +"', " +cantServ +" )");
}
catch (Exception e)
{
e.getMessage();
}
开发者_运维问答 }
db.close();
}
UsuariosSQLiteHelper bdLlena =
new UsuariosSQLiteHelper(this, "DBIncidentes", null, 1);
SQLiteDatabase db2 = bdLlena.getReadableDatabase();
if(db2 != null)
{
String query = "Select * FROM Moviles";
Cursor d = db2.rawQuery(query,null);
if (d.moveToFirst())
do {
Integer j = 1;
Integer idInterno = d.getInt(0);
String numMovil = d.getString(1);
String colMovil = d.getString(2);
String estado = d.getString(3);
String localidad = d.getString(4);
Integer cantServ = d.getInt(5);
TableRow tr = new TableRow(this);
tr.setId(idInterno);
tr.setOnClickListener(this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
//-------------------------------------------------
//seteo el campo Numero de Movil
TextView cmpNumMovil = new TextView(this);
cmpNumMovil.setId(200+j);
int colorInt = Color.parseColor(colMovil);
cmpNumMovil.setGravity(Gravity.CENTER);
cmpNumMovil.setText(numMovil);
cmpNumMovil.setBackgroundColor(colorInt);
cmpNumMovil.setTextColor(Color.BLACK);
cmpNumMovil.setWidth(10);
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
v.setBackgroundColor(Color.rgb(0, 0, 0));
tl.addView(v);
tr.addView(cmpNumMovil);
//----------------------------------------------------------------
//seteo el campo entidad
TextView cmpEstado = new TextView(this);
cmpEstado.setId(300+j);
cmpEstado.setText(estado);
cmpEstado.setGravity(Gravity.CENTER);
cmpEstado.setTextColor(Color.BLACK);
tr.addView(cmpEstado);
//----------------------------------------------------------------
TextView cmpLoc = new TextView(this);
cmpLoc.setId(300+j);
cmpLoc.setText(localidad);
cmpLoc.setGravity(Gravity.CENTER);
cmpLoc.setTextColor(Color.BLACK);
tr.addView(cmpLoc);
//----------------------------------------------------------------
TextView cmpCantServ = new TextView(this);
cmpCantServ.setId(300+j);
cmpCantServ.setText(cantServ);
cmpCantServ.setGravity(Gravity.CENTER);
cmpCantServ.setTextColor(Color.BLACK);
tr.addView(cmpCantServ);
j++;
} while(d.moveToNext());
}
db2.close();
}
catch (Exception e)
{
e.getMessage();
}
}
I use the same helper for the two tables, and my new table is full of data.. but it isn't displayed in my screen and i have the error of created and never closed..
In UsuariosSQLiteHelper
class, did you really implement method close()
?
try to implement the overridden method close() for database, and after every operation call close(), will cloase ur database...
@Override
public synchronized void close() {
if (myDataBase != null)
myDataBase.close();
super.close();
}
Hope u get my point...
精彩评论