android handle

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();
			}

		};

得到异常:

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)

分析:

在handle里面不能对适配器调用notify()。

解决:

将listAdapter.notify()注释掉。

你可能感兴趣的:(handle,Adapater)