我想添加到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