解决异常:Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:矩阵的秩代表什么 编辑:程序博客网 时间:2024/06/05 19:39
之前开发中遇到这个问题:
java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()
这个错误看字面意思也能理解,就是无法再没有looper的线程中创建handler
通常出现在我们在子线程中嵌套一个子线程的情况。因为子线程是相对于主线程而言的,不能生成子线程的子线程。
解决方案有两种:
1.在我们新建非法子线程的地方做修改:
//在UI线程中做线程的新建操作if (getActivity() != null) { getActivity().runOnUiThread(new Runnable() {@Overridepublic void run() {//新线程中的操作}});}
2.还是在我们新建非法子线程的地方做修改:
//传入一个mainLooperHandler handler = new Handler(Looper.getMainLooper());handler.post(new Runnable() {@Overridepublic void run() {//子线程中的操作}});
0 0
- 解决异常: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() inside AsyncTask
- 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() 解决方法
- 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() 异常
- 异常: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()
- studio 异常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()错误的解决
- 解决Can't create handler inside thread that has not called Looper.prepare()
- 错误BUG解决:Can't create handler inside thread that has not called Looper.prepare()
- 解决Can't create handler inside thread that has not called Looper.prepare()
- jquery input动态绑定onchange事件
- 动态规划
- HDU-3652-数位dp
- 《文本计算器》数学字符串转换公式进行运算并得到值
- Linux下系统调用编程socket(2)
- 解决异常:Can't create handler inside thread that has not called Looper.prepare()
- Android 入门之Intent应用
- php 简单的注册和登录,带数据库。适合新手学习。
- 解压tar.gz文件报错gzip: stdin: not in gzip format解决方法或者Error is not recoverable: exiting now
- C99的各类头文件
- H5适配逼疯人!这个方案或许能帮到你
- 第三章 数组与字符串
- 转载:《TypeScript 中文入门教程》
- ant design后台模板-1.前端环境搭建