android - SQLite database crash due to reopen already closed object -
android - SQLite database crash due to reopen already closed object -
i have databasehelper
public class databasehelper extends sqliteopenhelper { private static final string database_name = "name"; private static final int database_version = 1; private static databasehelper dbhelper; private context mtempctx = null; private databasehelper(context context) { super(context, database_name, null, database_version); mtempctx = context; } public static databasehelper getinstance(context context) { if (null == dbhelper) { dbhelper = new databasehelper(context); } homecoming dbhelper; } ...
my main activity tabs
import android.support.v7.app.actionbaractivity; public class mainactivity extends actionbaractivity { // private adview madview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); databasehelper.getinstance(getapplicationcontext()) .getwritabledatabase(); actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); ...
and fragment in first tab
import android.support.v4.app.fragment; public class calendarfragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { ... cursor cur = getactivity().getcontentresolver().query( table.content_uri, table.projection, null, null, null);
this query makes
06-18 08:21:05.854: e/androidruntime(1023): caused by: java.lang.illegalstateexception: effort re-open already-closed object: sqlitequery: ...
this code works on 4.2.2 , 4.3, 4.4, crash on 4.1 , 2.3.7. after reading few tutorials , questions here still didnt work me.
if want database operation after db.close ,then must phone call db.getwritabledatabase().
android database sqlite
Comments
Post a Comment