在调用此方法之前,游标已停用

时间:2014-11-24 21:54:59

标签: android simplecursoradapter android-cursoradapter android-cursor

我有一个CursorAdapter我在onLoadFinished()回调内部交换了数据。紧接着之后,我还需要为多个其他CursorAdapters使用相同的光标(下面仅示出1)。问题是,在光标data被转换到原始CursorAdapter后,我得到以下错误。如果我在应用中稍后的原始getCursor()CursorAdapter,则无误地运行。这是为什么 ? 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)

1 个答案:

答案 0 :(得分:2)

显然,由于代码中存在一些问题,onLoadFinished()回调几乎同时被调用了两次,这可能对data Cursor没有产生很好的影响。如果遇到此问题,请仔细检查您的代码。