I am trying to fix a ‘finalize’ error that I have been battling with allday. This issue still persists after me trying a number of different database and cursor’.close()’ methods.
The code shown is how it stands now. It would be great if someone could guide me on closing my cursor and db’s in the correct manner, as at the moment if I close one, it seems to conflict with the other!
At the moment I am trying to set an ‘EditText’ with a retrieved string value from a object method set within the ‘onCreate’ method of a ‘AddAppointmentContact’ class that is called from the Intent of a dialog list.
Currently I am getting this error:
Error:
02-01 21:23:18.947: E/Cursor(274): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.example.flybase2/databases/persons_name, table = contactsTable, query = SELECT _id, persons_name, persons_telephone, persons_email, persons_comments FROM contactsTable WHER
I run similar code else where in my code and this works fine.
This is the code bundled with the ID of the name I have selected from a listview that holds the dialog:
else if (items[item].equals("Add Appointment")) {
Intent conAdd = new Intent("com.example.flybase2.AddAppointmentContact");
conAdd.putExtra("newpassedID", idToPass);
startActivity(conAdd);
And the ‘AddAppointmentContact’ class that is opened:
Bundle extras = getIntent().getExtras();
sentID = extras.getLong("newPassedID");
DBHandlerApp NameAppointPass = new DBHandlerApp(this, null, null);
NameAppointPass.open();
String nameReturned = NameAppointPass.getName(sentID);
setName = (EditText) findViewById(R.id.inputAppName);
setName.setText(nameReturned);
And the ‘.getName()’ method:
public String getName(long passedID) {
String [] columns = new String[]{KEY_ROWAPPID, KEY_NAMEAPP, KEY_TYPEAPP, KEY_TIMEAPP, KEY_DATEAPP, KEY_COMMENTAPP};
Cursor c = ourDatabase.query(DATABASE_TABLEAPP, columns, KEY_ROWAPPID + "=" + passedID, null, null, null, null);
if(c != null && c.getCount() > 0)
{
c.moveToFirst();
String name = c.getString(1);
return name;
}
return null;
Also agreeing that you must close your
Cursor. Try this: