Android 的View不是執行緒安全的.

jackie_gnu發表於2011-09-23

當在UI 執行緒之外更新view元件時會出現exception. 

 

E/AndroidRuntime( 4371): FATAL EXCEPTION: Thread-10
E/AndroidRuntime( 4371): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
E/AndroidRuntime( 4371):        at android.view.ViewRoot.checkThread(ViewRoot.java:3020)
E/AndroidRuntime( 4371):        at android.view.ViewRoot.requestLayout(ViewRoot.java:634)
E/AndroidRuntime( 4371):        at android.view.View.requestLayout(View.java:8320)
E/AndroidRuntime( 4371):        at android.view.View.requestLayout(View.java:8320)
E/AndroidRuntime( 4371):        at android.view.View.requestLayout(View.java:8320)
E/AndroidRuntime( 4371):        at android.view.View.requestLayout(View.java:8320)
E/AndroidRuntime( 4371):        at android.view.View.requestLayout(View.java:8320)
E/AndroidRuntime( 4371):        at android.widget.TextView.checkForRelayout(TextView.java:5608)
E/AndroidRuntime( 4371):        at android.widget.TextView.setText(TextView.java:2783)
E/AndroidRuntime( 4371):        at android.widget.TextView.setText(TextView.java:2644)
E/AndroidRuntime( 4371):        at android.widget.TextView.setText(TextView.java:2619)
E/AndroidRuntime( 4371):        at com.example.test.UIThreadctivity$UIThreadUpdate.run(UIThreadctivity.java:42)

相關文章