0

我从我的内容提供者返回一个 MergeCursor 实例,包装来自同一内容提供者的游标。听起来很奇怪,但我需要它来进行数据聚合。这是代码:

Cursor filteredLatest = getContext().getContentResolver().query(Latest.CONTENT_URI, ALL,
                    null, null, null);
return new MergeCursor(new Cursor[]{filteredLatest});

我不在setNotificationUri这里使用,因为filteredLatest光标已经设置了通知 uri。

一切都很顺利,我可以查看数据,直到我用新数据更新内容提供者。

然后它与

10-18 00:15:19.441: E/AndroidRuntime(31491): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 13
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:74)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.CursorWrapper.getLong(CursorWrapper.java:106)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.MergeCursor.getLong(MergeCursor.java:116)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.CursorWrapper.getLong(CursorWrapper.java:106)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.CursorAdapter.getItemId(CursorAdapter.java:220)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.AdapterView.rememberSyncState(AdapterView.java:1195)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:810)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:5998)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.CursorAdapter$MyDataSetObserver.onChanged(CursorAdapter.java:467)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.AbstractCursor.requery(AbstractCursor.java:137)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:234)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.CursorWrapper.requery(CursorWrapper.java:186)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.MergeCursor.requery(MergeCursor.java:228)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.CursorWrapper.requery(CursorWrapper.java:186)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.CursorAdapter.onContentChanged(CursorAdapter.java:443)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.widget.CursorAdapter$ChangeObserver.onChange(CursorAdapter.java:459)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.ContentObserver.onChange(ContentObserver.java:129)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:180)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.os.Handler.handleCallback(Handler.java:730)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.os.Looper.loop(Looper.java:137)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at android.app.ActivityThread.main(ActivityThread.java:5103)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at java.lang.reflect.Method.invokeNative(Native Method)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at java.lang.reflect.Method.invoke(Method.java:525)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-18 00:15:19.441: E/AndroidRuntime(31491):    at dalvik.system.NativeStart.main(Native Method)

我已经查看了MergeCursor代码,似乎包裹的光标被通知了数据更改并将 MergeCursor 的位置设置为-1。然后适配器也被通知更改并且它死了。

我不确定在哪里寻找错误。

4

1 回答 1

1

我的方法是错误的。在查看了Android 拨号器应用程序后,我决定编写自己的合并适配器,而不是使用有缺陷的 MergeCursor。

于 2013-10-18T09:13:19.553 回答