天天看點

解決The content of the adapter has changed but ListView did not receive a notification

問題分析:

log的資訊很簡單,就是在改動ListView内容後,沒有調用notifyDataSetChanged函數來更新,才導緻的異常。

- ::: E/AndroidRuntime(): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(, class com.handmark.pulltorefresh.library.PullToRefreshListView$b) with Adapter(class android.widget.HeaderViewListAdapter)]
- ::: E/AndroidRuntime():    at android.widget.ListView.layoutChildren(ListView.java:)
- ::: E/AndroidRuntime():    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:)
- ::: E/AndroidRuntime():    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:)
- ::: E/AndroidRuntime():    at android.view.Choreographer.doCallbacks(Choreographer.java:)
- ::: E/AndroidRuntime():    at android.view.Choreographer.doFrame(Choreographer.java:)
- ::: E/AndroidRuntime():    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:)
- ::: E/AndroidRuntime():    at android.os.Handler.handleCallback(Handler.java:)
- ::: E/AndroidRuntime():    at android.os.Handler.dispatchMessage(Handler.java:)
- ::: E/AndroidRuntime():    at android.os.Looper.loop(Looper.java:)
- ::: E/AndroidRuntime():    at android.app.ActivityThread.main(ActivityThread.java:)
- ::: E/AndroidRuntime():    at java.lang.reflect.Method.invokeNative(Native Method)
- ::: E/AndroidRuntime():    at java.lang.reflect.Method.invoke(Method.java:)
- ::: E/AndroidRuntime():    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:)
- ::: E/AndroidRuntime():    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:)
- ::: E/AndroidRuntime():    at dalvik.system.NativeStart.main(Native Method)
           

解決方法:

1.首先保證不線上程中調用notifyDataSetChanged函數。

2.在每次涉及到修改ListView内容時,一定要調用notifyDataSetChanged即可。

繼續閱讀