Note that there are some explanatory texts on larger screens.

plurals
  1. POListView SimpleCursorAdapter Updated Asynchronously
    primarykey
    data
    text
    <p>I have a class that has a SimpleCursorAdapter as a field. That adapter is used feed a listview that has a a viewBinder.</p> <p>I have an asynchronous task that runs that adds an entry to the database and then updates the cursor. </p> <p>In testing, if I click too quickly on the button that runs the async process, I get an error:</p> <pre><code>java.lang.RuntimeException: An error occured while executing doInBackground() ... Caused by: java.lang.IllegalStateException: database [path_to_my_db] already closed </code></pre> <p>The code WORKS perfectly - unless... the user clicks the save button rapidly in succession... I'm new to all of this, so any input would be greatly appreciated!</p> <p>Here is a stripped down version of what I'm trying to do:</p> <pre><code>public class MyActivity extends Activity { private DatabaseConnector connector; // this is my class for managing SQLite private SimpleCursorAdapter adapter; .... @Override public void onCreate(Bundle savedInstanceState){ ... myListView = (ListView)findViewById(R.id.my_list_view); String[] = new String{"This", "part", "is", "working"}; int[] to = new int[] {1,2,3,4}; // again, this is working... adapter = new SimpleCursorAdapter(this, R.layout.my_list_item_row, null, from, to); adapter.setViewBinder(new ViewBinder(){ ... // this is all working ... // the viewBinder is for custom date formatting... again, all works }); myListView.setAdapter(adapter); } private class MyAsyncTask extends AsyncTask&lt;Context, Void, ExerciseInstanceViewModel&gt;{ MyViewModel vm; // this viewModel has a cursor member... public MyAsyncTask([variables-all-working]){ } @Override protected MyViewModel doInBackground(Context... params) { connector = new DatabaseConnector(MyActivity.this); connector.open(); // TODO: Getting 'did not close database error here...' vm = connector.runMethodThatIncludesCursorInReturnType([input-paramters-working]); return vm; } // use the cursor returned from the doInBackground method @Override protected void onPostExecute(MyViewModel result){ super.onPostExecute(result); // set instance fields in outer class...; // set textView, progressBar, etc.. if (result.MyCursor != null) { adapter.changeCursor(result.MyCursor); } connector.close(); // aren't i closing the db here??? [Code to reload page with next detail items] } } } </code></pre>
    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