Android开发报错 Can't create handler inside thread that has not called Looper.prepare()
2016-08-01 16:11
645 查看
原因分析:在线程中调用了Toast(或者Dialog提示)。
解决方法:在调用Toast(或者AlertDialog)的地方的前面加上Looper.prepare(),后边加上Looper.loop()即可解决问题;也就是说用Looper.prepare()和Looper.loop()把Toast前后包起来。
Looper.loop()会死循环堵塞线程
其他解决方案:
在主线程中定义handler,
然后在子线程中用handler.post如下:
解决方法:在调用Toast(或者AlertDialog)的地方的前面加上Looper.prepare(),后边加上Looper.loop()即可解决问题;也就是说用Looper.prepare()和Looper.loop()把Toast前后包起来。
Looper.loop()会死循环堵塞线程
其他解决方案:
在主线程中定义handler,
然后在子线程中用handler.post如下:
new Runnable(){ @Override public void run() { mHandler.post(new Runnable() { @Override public void run() { Toast.makeText(mApp.getApplicationContext(),"服务器异常,请稍后重试",Toast.LENGTH_SHORT).show(); } }); } }.run();
相关文章推荐
- android 开发遇到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()
- Android蓝牙开发,报BluetoothAdapter﹕ 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()
- Android: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()
- 记录一次因为Android版本不同导致的crash异常: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()
- Android中的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()
- Android在Activity中启动一个新进程报错: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()
- android异常收集-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
- 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()
- java.lang.RuntimeException: 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()