Skip to content Skip to sidebar Skip to footer

Android Java.lang.illegalstateexception Database Already Closed

I have a really weird problem that i am not able to reproduce neither on emulator or on any of the tested android devices. I have a SQlite Database controller that holds all of min

Solution 1:

Please put that second cursor.close(); inside the else blocks follows

public boolean tableExists(String tableName) {   
  if(db==null || !db.isOpen()) db =  dbhelper.getWritableDatabase();      
  Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='"+tableName+"'", null);
       if(cursor!=null) {
           if(cursor.getCount()>0) {
              cursor.close();
              return true;
             }
          else{
                  cursor.close();
              }  
             }
      return false;  
    }

Post a Comment for "Android Java.lang.illegalstateexception Database Already Closed"