我想添加到EditText
幾ClickableSpan
in AsynkTask
。android:無法在doInBackground中調用Looper.prepare()的線程內創建處理程序
我用接下來的代碼如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
et = (EditText)findViewById(R.id.et);
...
class makeLinksAsync extends AsyncTask<String, String, EditText> {
private EditText buffer;
protected EditText doInBackground(String... texts) {
buffer = new EditText(context); // here is an error
SpannableString spanStr = new SpannableString("word");
...
buffer.append(spanStr);
return buffer;
}
protected void onPostExecute(EditText linkedText) {
ed.setText(linkedText.getText());
}
}
}
當我測試了不同的仿真器和我自己的設備上使用的Android2.3一切都很好,這個代碼並且該代碼運行良好。但是,在上傳apk到GooglePlay後,我得到了幾處提到的行中有錯誤的崩潰報告。 日誌報告是下一個:
java.lang.RuntimeException: An error occured while executing doInBackground()
...
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
...
at lubart.apps.dictionary.DictionaryActivity$makeLinksAsync.doInBackground(DictionaryActivity.java:2233) // this line is mentioned in code
而且我應該說,出現不能在所有設備這個問題,一些用戶報告說,一切工作正常。
你能幫我解決這個錯誤嗎?
非常感謝!它幫助! – lubart 2013-04-04 19:23:01