改變方向時,我得到一個IllegalStateException。我有一個使用SimpleCursorAdapter和ContentProvider的listView。 任何想法是什麼導致此異常?Android IllegalStateException異常改變getView中的方向改變SimplecursorAdapter
編輯
我一定是改變的東西,因爲我只看到異常從動作條微調選擇項目時,然後改變方向。 動作欄微調器有三項:顯示全部,顯示日期,顯示位置
當用戶選擇一個時,它會查詢數據庫(請參閱onNavigationItemSelected())。我嘗試關閉onStop()中的光標,但沒有解決問題。 哪裏會是合適的地方關閉它?
在MainActivity:
private Cursor mCursor = null;
public void onCreate() {
mSimpleCursorAdapter = new SpecialAdapter(this,
R.layout.row,
null,
//cursor,
PROJECTION,
new int[] { R.id.titleID, R.id.dateTimeOrLocationID1 , R.id.dateTimeOrLocationID2 },
CursorAdapter.NO_SELECTION);
mListView = (ListView) findViewById(android.R.id.list);
mListView.setAdapter(mSimpleCursorAdapter);
mOnNavigationListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int position, long itemId) {
switch(position) {
case 0:
mCursor = getContentResolver().query(ReminderContentProvider.CONTENT_URI, PROJECTION, null, null, null);
break;
case 1:
mCursor = getContentResolver().query(ReminderContentProvider.CONTENT_URI, PROJECTION, " Date NOT NULL", null, null);
break;
case 2:
mCursor = getContentResolver().query(ReminderContentProvider.CONTENT_URI, PROJECTION, " Address NOT NULL", null, null);
break;
default:
break;
}
getLoaderManager().restartLoader(0, null, MainActivity.this);
return true;
}
};
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
CursorLoader loader = new CursorLoader(this, ReminderContentProvider.CONTENT_URI, PROJECTION, null, null, null);
return loader;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mSimpleCursorAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mSimpleCursorAdapter.swapCursor(null);
}
SimpleCursorAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Cursor mCursor = (Cursor) getItem(position); // exception
if(mCursor != null)
{
........
}
}
編輯
E/ACRA (3348): com.example.locationreminder fatal error : attempt to re-open an already-closed object: SQLiteQuery: SELECT _id, Title, Date, Address, Radius, Repetition FROM reminder
E/ACRA (3348): java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT _id, Title, Date, Address, Radius, Repetition FROM reminder
E/ACRA (3348): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
E/ACRA (3348): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58)
E/ACRA (3348): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:151)
E/ACRA (3348): at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:124)
E/ACRA (3348): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:213)
E/ACRA (3348): at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162)
E/ACRA (3348): at android.widget.CursorAdapter.getItem(CursorAdapter.java:207)
E/ACRA (3348): at com.example.locationreminder.SpecialAdapter.getView(SpecialAdapter.java:51)
E/ACRA (3348): at android.widget.AbsListView.obtainView(AbsListView.java:2271)
E/ACRA (3348): at android.widget.ListView.makeAndAddView(ListView.java:1769)
顯示異常。 – kriomant
我添加了例外日誌 – user2246120