Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:左程云面试算法指南 编辑:程序博客网 时间:2024/06/07 05:03
报错:Can't create handler inside thread that has not called Looper.prepare()
原因:Toast不能直接在子线程中调用显示
场景:在子线程中进行了数据操作,并且用handler发送刷新ui并打印Toast
原代码如下:
new Thread(new Runnable() { public void run() { try { EMClient.getInstance().groupManager().addUsersToGroup(groupId, newmembers); Qiuutil.ShortToast("已经添加群成员"); listuser.get(position).put("1","1"); handler.sendEmptyMessageDelayed(2,500); } catch (Exception e) { Qiuutil.ShortToast("添加失败"); } }}).start();
报错之后加上Looper.prepare();Looper.loop();中包裹handler和Toast 就不会报错,代码如下:
new Thread(new Runnable() { public void run() { try { EMClient.getInstance().groupManager().addUsersToGroup(groupId, newmembers); Looper.prepare(); Qiuutil.ShortToast("已经添加群成员"); listuser.get(position).put("1","1"); handler.sendEmptyMessageDelayed(2,500); Looper.loop(); } catch (Exception e) { Qiuutil.ShortToast("添加失败"); } }}).start();
阅读全文
0 0
- 解决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()
- 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()
- 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() 解决方法
- 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()错误-安卓编程
- 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:使用 toggle 切换 css 时,checkbox不能选中的解决方法;在checkbox中"放入"文字
- 3.3V与5V单片机通讯电路原理图
- JavaWeb 17-6-2
- win10 vpn 安装手册
- Linux操作命令
- Can't create handler inside thread that has not called Looper.prepare()
- Clion c c++ 开发环境配置
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
- Elasticsearch小记之sort
- iOS中UILabel设置可变长度并加圆角后尾部出现黑线
- 如何优化JAVA代码及提高效率
- SpringMvc4.3.8搭建记录
- (32)快速排序
- 之江学院 2017 J qwb又偷懒了 树状数组