2013-08-17 2 views
0

방향을 변경할 때 IllegalStateException이 발생합니다. 나는 SimpleCursorAdapter과 ContentProvider를 사용하여 listView를 가지고있다. 이 예외의 원인은 무엇입니까? 나는 액션 바 스피너에서 항목을 선택하는 경우에만 예외를 참조하고 방향을 변경하기 때문에SimplecursorAdapter의 getView에서 방향 변경시 Android IllegalStateException이 발생합니다.

편집

내가 뭔가를 변경해야했습니다. 작업 표시 줄 스피너에는 Show All, Show Date, Show Location의 세 항목이 있습니다.

사용자가 데이터베이스를 선택하면 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) 
+0

예외를 표시하십시오. – kriomant

+0

예외 로그를 ​​추가했습니다 – user2246120

답변

1

나는 이것이 실패의 이유는 잘 모르겠지만, 버그가 명확있다 귀하의 코드 :로드와 수동 커서 관리를 섞어보십시오. 어. OnNavigationItemSelected에서 changeCursor으로 전화하십시오. 몇 가지 문제가 있습니다 : UI 스레드에서

  1. 당신 부하 데이터 로더는이
  2. changeCursor 오래된 커서를 닫 방지하기 위해 존재한다. 그러나이 커서는 loader가 소유하고 있으므로 닫지 않아야합니다. 호출 후 로더에 의해 닫힙니다. OnLoadFinished
  3. 수동으로 만든 커서가 닫힌 곳이 명확하지 않습니다.

OnNavigationItemSelected에서 수행해야 할 작업은 새 쿼리 매개 변수로 로더를 다시 시작하는 것입니다.

+0

감사합니다. 나는 코드를 편집하고 changeCursor를 제거했다. 예외는 이제 사라졌지 만 getLoaderManager(). restartLoader()를 추가했지만 listview는 더 이상 업데이트되지 않습니다. 내가 뭘 놓치고 있니? – user2246120