android - Finalizing a Cursor that has not been deactivated or closed -
android - Finalizing a Cursor that has not been deactivated or closed -
okay, new android developping, or developping , getting error. trying everytime user select spinner item programme creates list. have databasehelper class using getting results of list. problem is never create list, , gives error.
databasehelper methods activity uses;
public int[] searchbyletter(string letter) { // todo auto-generated method stub int[] results = new int[100]; int count = 0; string[] columns = new string[] { key_mineralid }; cursor c = minerals.query(database_table, columns, key_letter + "= '" + letter + "'", null, null, null, null); if (c.movetofirst()) { results[count] = c.getint(c.getcolumnindex(key_mineralid)); } while (c.movetonext()) { count++; results[count] = c.getint(c.getcolumnindex(key_mineralid)); } c.close(); homecoming results; } public string getname(int _id) { // todo auto-generated method stub string[] columns = new string[] { key_name }; cursor c = minerals.query(database_table, columns, key_mineralid + "=" + _id, null, null, null, null); c.movetofirst(); int iname = c.getcolumnindex(key_name); string result = c.getstring(iname); c.close(); homecoming result; }
this listactivity class;
public class az extends listactivity { string[] spazpaht = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "y", "z" }; arraylist<azorder> azorder; azorderadapter azorderadapter; spinner spaz; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.az); arrayadapter<string> spazadpt = new arrayadapter<string>(az.this, android.r.layout.simple_spinner_item, spazpaht); spaz = (spinner) findviewbyid(r.id.spaz); spaz.setadapter(spazadpt); azorder = new arraylist<azorder>(); this.azorderadapter = new azorderadapter(az.this, r.layout.az, azorder); setlistadapter(azorderadapter); spaz.setonitemselectedlistener(new onitemselectedlistener() { public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { getsearches(); } public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub getsearches(); } }); } private void getsearches() { databasehelper mydbhelper = new databasehelper(az.this); seek { mydbhelper.createdatabase(); } grab (ioexception e) { // todo: handle exception e.printstacktrace(); } seek { mydbhelper.opendatabase(); } grab (sqlexception sqle) { throw sqle; // todo: handle exception } int position = spaz.getselecteditemposition(); string letter = spazpaht[position]; int[] results = mydbhelper.searchbyletter(letter); seek { azorder = new arraylist<azorder>(); azorder azo = new azorder(); (int = 0; < results.length; i++) { azo.setname(mydbhelper.getname(results[i])); azo.setmineral_id(results[i]); azorder.add(azo); } thread.sleep(5000); log.i("array", "" + azorder.size()); } grab (exception e) { // todo: handle exception log.e("background_proc", e.getmessage()); } mydbhelper.close(); }
this error getting
e/cursor(295): finalizing cursor has not been deactivated or closed. database = /data/data/com.mineralidentifier.degosa.test1/databases/ minerals, table = minerals, query = select minerals_name minerals _id=0 e/cursor(295): android.database.sqlite.databaseobjectnotclosedexception: application did not close cursor or database object opened here e/cursor(295): @ android.database.sqlite.sqlitecursor.<init> (sqlitecursor.java:210) e/cursor(295): @ android.database.sqlite.sqlitedirectcursordriver.query (sqlitedirectcursordriver.java:53)
looks cursor isn't beingness closed. see have c.close(), might not reach because exception beingness thrown before it. and, exception beingness masked databaseobjectnotclosedexception ends beingness thrown masking original one. it's best wrap in clause ensure closed regardless of exception beingness thrown or not.
cursor c = ... seek { ... } { c.close(); }
if may tell real problem is. unfortunately, since don't see total exception's stacktrace can't see databaseobjectnotclosedexception thrown in code. can see in android code it's thrown from, can't see past sqlitedirectcursordriver.query.
android sqlite cursor
Comments
Post a Comment