can't create handler inside thread that has not called Looper.prepare
2016-12-31 22:17
579 查看
出现原因:不是在主线程(UI线程)中
demo
下面的代码会抛出如题的异常信息new Thread(new Runnable() { @Override public void run() { try { // 模拟耗时操作 Thread.sleep(1000 * 2); Toast.makeText(getApplicationContext(), "下载成功", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } });
常用解决办法
使用 android.os.Handler使用 android.app.Activity 类的 public final void android.app.Activity.runOnUiThread(Runnable action) 方法
相关文章推荐
- Can't create handler inside thread that has not called Looper.prepare()
- 解决Can't create handler inside thread that has not called Looper.prepare() inside AsyncTask
- Can't create handler inside thread that has not called Looper.prepare()
- Unity3d for android 访问UI控件报错 Can\'t create handler inside thread that has not called Looper.prepare()
- Dialog中使用handler时报:Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()的终极解决方法
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Android开发报错 Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- 异常:Can't create handler inside thread that has not called Looper.prepare()
- Android java.lang.RuntimeException: Can\'t create handler inside thread that has not called Looper.prepare()
- 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Looper如何和一个线程进行绑定,以及Android中的Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()
- Android : Can't create handler inside thread that has not called Looper.prepare()