0

我正在获取响应和解析的数据并存储在字符串中,现在我在 Edittext 中显示我得到以下异常。我在 AsyncTask 中得到响应和解析

    05-02 10:13:56.797: W/System.err(17935): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
    05-02 10:13:56.867: W/System.err(17935):    at android.view.ViewRoot.checkThread(ViewRoot.java:2812)
    05-02 10:13:56.867: W/System.err(17935):    at android.view.ViewRoot.invalidateChild(ViewRoot.java:607)
    05-02 10:13:56.867: W/System.err(17935):    at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:633)
    05-02 10:13:56.867: W/System.err(17935):    at android.view.ViewGroup.invalidateChild(ViewGroup.java:2505)
    05-02 10:13:56.867: W/System.err(17935):    at android.view.View.invalidate(View.java:5115)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView.invalidateCursor(TextView.java:3661)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView.spanChange(TextView.java:6352)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:6477)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:906)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:514)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.Selection.setSelection(Selection.java:74)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.Selection.setSelection(Selection.java:85)
    05-02 10:13:56.867: W/System.err(17935):    at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:497)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView.setText(TextView.java:2712)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView.setText(TextView.java:2592)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.EditText.setText(EditText.java:149)
    05-02 10:13:56.867: W/System.err(17935):    at android.widget.TextView.setText(TextView.java:2567)
    05-02 10:13:56.867: W/System.err(17935):    at com.smartbuzz.contax.Profil.getServerResponse(Profil.java:262)
    05-02 10:13:56.877: W/System.err(17935):    at com.smartbuzz.contax.Profil$Testing.doInBackground(Profil.java:357)
    05-02 10:13:56.877: W/System.err(17935):    at com.smartbuzz.contax.Profil$Testing.doInBackground(Profil.java:1)
    05-02 10:13:56.877: W/System.err(17935):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    05-02 10:13:56.877: W/System.err(17935):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    05-02 10:13:56.877: W/System.err(17935):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    05-02 10:13:56.877: W/System.err(17935):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
    05-02 10:13:56.877: W/System.err(17935):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
4

1 回答 1

5

您正在从工作线程调用您的setText()方法。EditText所有 UI 元素只能从主线程更新。

在您的中,应该调用AsyncTask该方法而不是setText()onPostExecute()doInBackground()

于 2013-05-02T05:06:22.017 回答