title: Why ormlite occur error [java.lang.IllegalStateException: attempt to re-open an already-closed object]?
body: <p>This is code of database helper, i using ORMLite:</p>
  
  <pre><code>object DatabaseHelper : OrmLiteSqliteOpenHelper(App.instance, "test.db", null, 1) {
  
      override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {            
          TableUtils.createTableIfNotExists(connectionSource, M_Data::class.java)
      }
  
      override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?, oldVersion: Int, newVersion: Int) {
  
              TableUtils.dropTable&lt;M_Data, Any&gt;(connectionSource, M_Data::class.java, true)
              onCreate(database, connectionSource)    
      }
  
  }
  </code></pre>
  
  <p>This is code of DAO:</p>
  
  <pre><code>@DatabaseTable(tableName = "m_data")
  data class M_Data(
  
          @DatabaseField(generatedId = true)
          var id: Int? = null,
  
          @DatabaseField
          var username: String="",
  
          @DatabaseField
          var insert_date: String = ""
  )
  class M_DataDao
  {
      companion object {
          lateinit var dao: Dao&lt;M_Data, Int&gt;
      }
  
      init {
          dao = DatabaseHelper.getDao(M_Data::class.java)
      }
  
      fun add(table: M_Data) = dao.createOrUpdate(table)
  
      fun update(table: M_Data) = dao.update(table)
  
      fun delete(table: M_Data) = dao.delete(table)
  
      fun queryForAll() = dao.queryForAll()
  
      fun removeAll() {
          for (table in queryForAll()) {
              dao.delete(table)
          }
      }    
       fun getListUserAddData(username:String):List&lt;Array&lt;String&gt;&gt;
  {
       val sql="select username from  M_Data"
      val rawResults = dao.queryRaw(sql)
  
      val results = rawResults.getResults()
      return results
  }
  }
  </code></pre>
  
  <p>In my Activity , i process get all data:</p>
  
  <pre><code>val data= M_DataDao()
  var listData=data.getListUserAddData("user")
  </code></pre>
  
  <p>I had close connect when exit:</p>
  
  <pre><code>override fun onDestroy() {
          super.onDestroy()
          DatabaseHelper.close()
      }
  </code></pre>
  
  <p>Steps occur error:</p>
  
  <p>Step 1: Open App and get Data: OK.</p>
  
  <p>Step 2: Close App</p>
  
  <p>Step 3: Open App again: occur a exception:</p>
  
  <pre><code>Process: com.example.son.kotlinandroiddemo, PID: 14642
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.son.kotlinandroiddemo/com.example.son.kotlinandroiddemo.ListData}: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.example.son.kotlinandroiddemo/databases/test.db
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                        at android.app.ActivityThread.-wrap11(Unknown Source:0)
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                        at android.os.Handler.dispatchMessage(Handler.java:106)
                        at android.os.Looper.loop(Looper.java:164)
                        at android.app.ActivityThread.main(ActivityThread.java:6494)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                     Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.example.son.kotlinandroiddemo/databases/test.db
                        at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
                        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1388)
                        at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1331)
                        at com.j256.ormlite.android.compat.JellyBeanApiCompatibility.rawQuery(JellyBeanApiCompatibility.java:21)
                        at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:193)
                        at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:72)
                        at com.j256.ormlite.stmt.SelectIterator.&lt;init&gt;(SelectIterator.java:57)
                        at com.j256.ormlite.stmt.RawResultsImpl.&lt;init&gt;(RawResultsImpl.java:30)
                        at com.j256.ormlite.stmt.StatementExecutor.queryRaw(StatementExecutor.java:276)
                        at com.j256.ormlite.dao.BaseDaoImpl.queryRaw(BaseDaoImpl.java:619)
                        at com.example.son.kotlinandroiddemo.db.dao.M_DataDao.getListUserAddData(M_Data.kt:49)
                        at com.example.son.kotlinandroiddemo.ListData.generateData(ListData.kt:35)
                        at com.example.son.kotlinandroiddemo.ListData.onCreate(ListData.kt:28)
                        at android.app.Activity.performCreate(Activity.java:6999)
                        at android.app.Activity.performCreate(Activity.java:6990)
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                        at android.os.Handler.dispatchMessage(Handler.java:106) 
                        at android.os.Looper.loop(Looper.java:164) 
                        at android.app.ActivityThread.main(ActivityThread.java:6494) 
  </code></pre>
  
  <p>Why ormlite occur error [java.lang.IllegalStateException: attempt to re-open an already-closed object]?
  How can fix this error?
  Thanks all.</p>