Note that there are some explanatory texts on larger screens.

plurals
  1. POIllegalStateException - Support LoaderManager with AutocompleteTextView
    text
    copied!<p>One of the benefits I thought of using CursorLoaders and Loadermanagers was that you didn't need to manually manage the lifecycle of the cursor. So I used a loadermanager to bind an adapter to an AutoCompleteTextView using the support package.</p> <p>It works quite well except that it randomly throws an error saying "IllegalStateException - attempt to re-open an already closed object". Surely that's not supposed to happen if we're using the loader manager?</p> <p>Here's the code:</p> <pre><code>package com.bhagwad.tennis; import android.appwidget.AppWidgetManager; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter.CursorToStringConverter; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.view.View.OnClickListener; import android.widget.AutoCompleteTextView; import android.widget.Button; import com.bhagwad.tennis.TennisSchedule.TennisScheduleColumns; public class WidgetConfiguration extends FragmentActivity implements OnClickListener, LoaderCallbacks&lt;Cursor&gt; { Button mSaveWidget; AutoCompleteTextView mPlayerName; int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; String mSelection =""; SimpleCursorAdapter mAdapter; public static String PREFS = "com.bhagwad.tennis.appwidget"; public static final String PREFS_PREFIX_KEY = "prefix_"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.widget_configuration); mPlayerName = (AutoCompleteTextView) findViewById(R.id.edit_filter); mPlayerName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (!s.equals("")) mSelection = s.toString(); else mSelection = ""; getSupportLoaderManager().restartLoader(0, null, WidgetConfiguration.this); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); // Set up the adapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, new String[] {TennisScheduleColumns.PLAYER_NAME}, new int[] {android.R.id.text1}, 0); mAdapter.setCursorToStringConverter(new CursorToStringConverter() { @Override public CharSequence convertToString(Cursor c) { return c.getString(c.getColumnIndexOrThrow(TennisScheduleColumns.PLAYER_NAME)); } }); mPlayerName.setAdapter(mAdapter); getSupportLoaderManager().initLoader(0, null, this); } @Override public Loader&lt;Cursor&gt; onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(this, TennisScheduleColumns.CONTENT_URI_PLAYERS, new String[] {TennisScheduleColumns._ID, TennisScheduleColumns.PLAYER_NAME}, TennisScheduleColumns.PLAYER_NAME + " LIKE ?", new String[] {"%"+mSelection+"%"}, null); } @Override public void onLoaderReset(Loader&lt;Cursor&gt; arg0) { mAdapter.swapCursor(null); } @Override public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) { mAdapter.swapCursor(data); } } </code></pre> <p>Here's the error stack:</p> <pre><code>08-16 22:21:23.244: E/AndroidRuntime(25475): java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, player_name FROM players WHERE (player_name LIKE ?)) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:33) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:82) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:147) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:178) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.support.v4.widget.CursorAdapter.getItem(CursorAdapter.java:213) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.widget.AutoCompleteTextView.buildImeCompletions(AutoCompleteTextView.java:1113) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1072) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:950) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:932) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.os.Handler.dispatchMessage(Handler.java:99) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.os.Looper.loop(Looper.java:137) 08-16 22:21:23.244: E/AndroidRuntime(25475): at android.app.ActivityThread.main(ActivityThread.java:4507) </code></pre> <p>Any ideas on what could be wrong?</p>
 

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