4
我有一個CursorAdapter
,我將數據交換到onLoadFinished()
回調中。之後,我還需要使用相同的光標來處理多個其他CursorAdapters
(下面僅顯示1個)。問題是,光標data
被交換到原始CursorAdapter
後,我得到以下錯誤。如果我在原來的CursorAdapter
之後在應用中使用getCursor()
,那麼它的工作原理沒有任何錯誤。這是爲什麼 ?異步或swapCursor()
是什麼?我以爲這麼初始,但我試圖將data
Cursor
直接設置到其他CursorAdapters
它仍然有我的錯誤。那麼是什麼給了?有任何想法嗎 ?在調用此方法之前,光標被停用
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data)
{
mAccountsCursorAdapter.swapCursor(data);
// create new cursor adapter
Cursor cursor = new CursorWrapper(mAccountsCursorAdapter.getCursor());
mNewAccountsCursorAdapter.swapCursor(cursor);
}
錯誤如下:
android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:139)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at android.database.CursorWrapper.getString(CursorWrapper.java:114)
at android.database.CursorWrapper.getString(CursorWrapper.java:114)
at android.support.v4.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:135)
at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:197)
at android.widget.Spinner.onMeasure(Spinner.java:507)
at android.view.View.measure(View.java:17430)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
at android.view.View.measure(View.java:17430)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1260)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.widget.ScrollView.onMeasure(ScrollView.java:337)
at android.view.View.measure(View.java:17430)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
at android.view.View.measure(View.java:17430)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1141)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
你可以更深入地解釋這一點嗎?什麼可能導致'onLoadFinished()'連續調用兩次?我目前正在處理同樣的症狀。 – 2015-07-06 10:33:19
我真的不記得爲什麼onLoadFinished()在我的用例中被調用過兩次。即使我記得,它可能與您的使用案例不一樣。這些問題實際上取決於每個實現,因此它們可能會有很大的差異,這可能是爲什麼我沒有詳細描述當時的實際原因。回想起來,我可能還會補充細節。但不幸的是,時間已過去。對於你的情況,嘗試使用內置的AS調試器來調試你的代碼,我發現它在這種情況下非常有用。 – 2015-07-06 10:38:38
是的,現在已經調試了一段時間,像我的情況下的接縫可能與我調用'initLoader()'的地方有關。它看起來像不喜歡我改變方向後再次調用它。 – 2015-07-06 10:46:07