我在我的应用程序的两个活动中使用 PullToRefresh 库。我知道,这个库已被弃用,但它非常有用,它不仅可以从顶部处理刷新,还可以从底部处理。但它有一个问题:这个日志很少导致应用程序崩溃:
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class com.handmark.pulltorefresh.library.PullToRefreshListView$InternalListViewSDK9) with Adapter(class android.widget.HeaderViewListAdapter)]
at android.widget.ListView.layoutChildren(ListView.java:1551)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:4218)
at android.view.View.dispatchTouchEvent(View.java:7461)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2264)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1995)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2182)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1512)
at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2130)
at android.view.View.dispatchPointerEvent(View.java:7641)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3613)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4804)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4783)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4875)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4854)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4894)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:530)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5328)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
这种崩溃很少发生,以至于我在频繁使用的几个月中只在我的设备上看到一次。但我在 Google Play 开发者控制台中看到用户的此日志的崩溃报告。
据我了解,这种崩溃不是发生在我的代码中,而是发生在 InternalListViewSDK9 类的 PullToRefresh 库的代码中。这是 InternalListViewSDK9 的代码:
@TargetApi(9)
final class InternalListViewSDK9 extends InternalListView {
public InternalListViewSDK9(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX,
int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
// Does all of the hard work...
OverscrollHelper.overScrollBy(PullToRefreshListView.this, deltaY, scrollY, isTouchEvent);
return returnValue;
}
}
考虑到我无法重现它,如何修复此错误?也许有可能压制它?