更新UI操作需要在主线程完成

04-01 14:55:33.526: E/AndroidRuntime(17238): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6795)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:973)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.ViewGroup.invalidateChild(ViewGroup.java:5100)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.View.invalidateInternal(View.java:12817)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.View.invalidate(View.java:12781)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.view.View.invalidate(View.java:12765)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.widget.TextView.checkForRelayout(TextView.java:7365)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.widget.TextView.setText(TextView.java:4413)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.widget.TextView.setText(TextView.java:4270)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at android.widget.TextView.setText(TextView.java:4245)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at com.cosw.tsm.sdk.test.ScanBlueDeviceActivity$3$1.run(ScanBlueDeviceActivity.java:96)
04-01 14:55:33.526: E/AndroidRuntime(17238): 	at java.lang.Thread.run(Thread.java:833)

异常场景:

在用户点击刷新页面按钮之后,将之前的ListView中数据项清掉(具体代码如下),生成最新的数据项,此时在子线程中操作导致出现异常异常

deviceList.clear();
singleDeviceAdapter.notifyDataSetChanged();
参考解决办法: Only the original thread that created a view hierarchy can touch its views——Handler的...


你可能感兴趣的:(Android)