handler = new Handler() { public void handleMessage(Message msg) { for (int i = 0; i < mBaikeComments.size(); i++) { // 將全部Baikecomment解析放到listView中 BaikeComment baikeComment = mBaikeComments.get(i); HashMap<String, String> map = new HashMap<String, String>(); map.put("talker", String.valueOf(baikeComment.getPlId())); map.put("commentContent", baikeComment.getPlBody()); listItem.add(map); } listAdapter.notify(); } };
獲得異常: java
11-07 10:29:22.764: E/AndroidRuntime(16074): FATAL EXCEPTION: main
11-07 10:29:22.764: E/AndroidRuntime(16074): java.lang.IllegalMonitorStateException: object not locked by thread before notify()
11-07 10:29:22.764: E/AndroidRuntime(16074): at java.lang.Object.notify(Native Method)
11-07 10:29:22.764: E/AndroidRuntime(16074): at com.dian.encyclopedia.activity.ShowCommentActivity$1.handleMessage(ShowCommentActivity.java:70)
11-07 10:29:22.764: E/AndroidRuntime(16074): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 10:29:22.764: E/AndroidRuntime(16074): at android.os.Looper.loop(Looper.java:153)
11-07 10:29:22.764: E/AndroidRuntime(16074): at android.app.ActivityThread.main(ActivityThread.java:5297)
11-07 10:29:22.764: E/AndroidRuntime(16074): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:29:22.764: E/AndroidRuntime(16074): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:29:22.764: E/AndroidRuntime(16074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
11-07 10:29:22.764: E/AndroidRuntime(16074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-07 10:29:22.764: E/AndroidRuntime(16074): at dalvik.system.NativeStart.main(Native Method) android
分析: app
在handle裏面不能對適配器調用notify()。 oop
解決: spa
將listAdapter.notify()註釋掉。 code