Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase not closed
    primarykey
    data
    text
    <p>I looked at other questions regarding this problem and tried their solutions, but it did not help me unfortunately.</p> <p>The problem is not of critical nature, meaning my program does not crash, it continues running, but anyway I would like not to have errors if possible.</p> <p>I am using <strong>AsyncTask</strong> class to create some objects and load them up into an array. Database I use is a file obtained from the net, therefore I have no DBhelper class. I open the DB inside of doInBackround of AsyncTask. Inside it I have try-catch where I do all my db related work.</p> <p>At first I had variables for <em>db</em> and <em>cursors</em> inside of the try statement and also I had closure of <em>db</em> and <em>cursors</em> in it at the end. I found one link saying try-catch-final should be used, so I did that, I moved variable declaration outsite of try-catch-final statement and managed closing of <em>db</em> and <em>cursor</em> variables in the <em>final</em> part, but still it does not help, errors are still here.</p> <p>Here are some errors, I won't C/P all of them:</p> <blockquote> <p>01-25 17:22:45.142: E/Database(333): close() was never explicitly called on database '/data/data/stet.cityapp/app_databases/baza.db</p> <p>01-25 17:22:45.142: E/Database(333): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here</p> <p>01-25 17:22:45.142: E/Database(333): at stetocina.cityapp.SplashScreen$LoadDB.doInBackground(SplashScreen.java:1)</p> <p>01-25 17:22:45.142: E/Database(333): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)</p> <p>01-25 17:22:45.142: E/Database(333): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)</p> </blockquote> <p>Outline of the code:</p> <pre><code>protected Boolean doInBackground(String... params) { SQLiteDatabase db = null; Cursor poisCursor = null, tmpCursor = null; String whereString; try { String DBpath = getDir("databases", 0).getAbsolutePath() + File.separator + "baza.db"; if (SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.OPEN_READONLY) == null) return false; db = SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); ... result = true; } catch (Exception e) { result = false; return result; } finally { if (!poisCursor.isClosed() || poisCursor != null) { poisCursor.deactivate(); poisCursor.close(); poisCursor = null; } if (!db.isOpen() || db != null) { db.close(); db = null; } } return result; </code></pre> <p>}</p> <p>Could there be some problem that I am doing it in an AsyncTask? In the <strong>onPostExecute</strong> methond of AsyncTaks, if everything went well and result is true, I open a new Activity, and while debugging I noticed that the error is displayed only when new activity is displayed and not immediatelly after exit from doInBackground.</p> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload