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()解决办法
android Toast提示异常:java.lang.RuntimeException: Can't create handler inside thread that has not called
原因是在子线程弹Toast了, 切记,Toast只能在UI线程弹出
解决办法:
new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub try {
Thread.sleep(1000);
handler.sendEmptyMessage(0);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}).start();
private Handler handler = new Handler() { @Override
public void handleMessage(Message msg) {
Toast.makeText(CommodityDetails.this, "修改失败!", Toast.LENGTH_SHORT).show();
} };
完美解决!!!
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()
- Android-java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
章出自:luchg技术交流 http://www.luchg.com 版权所有.本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源,谢谢. Android-java.lang.Runti ...
- android Toast提示异常:java.lang.RuntimeException: Can't create handler inside thread that has not called
Toast只能在UI线程弹出,解决此问题可以在Toast前后加两行代码,如下所示: Looper.prepare(); Toast.makeText(getApplicationContext(),& ...
- 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- Android 线程更新UI报错 : Can't create handler inside thread that has not called Looper.prepare()
MainActivity中有一个按钮,绑定了save方法 public void save(View view) { String title = titleText.getText().toStri ...
- Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()
问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 // handler监听网络请求,完成后操作回调函数 final Handler trigerGfHandler ...
- 【转】在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- 转 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- Android Exception 13(Can't create handler inside thread that has not called Looper.prepare())
10-12 17:02:55.500: E/AndroidRuntime(28343): FATAL EXCEPTION: Timer-2 10-12 17:02:55.500: E/AndroidR ...
随机推荐
- JAVA-Web05
1 HTTP协议特点 1)客户端->服务端(请求request)有三部份 a)请求行 b)请求头 c)请求的内容,如果没有,就是空白字符 2)服务端->客户端(响应respon ...
- UVA 11925 Generating Permutations 生成排列 (序列)
题意:要用一个有序的序列生成给定序列,操作有两种,一是交换前两个元素,二是把第一个元素移动到最后去. 思路有两种: 1.映射,把给定序列映射成有序的序列,然后按照同样的替换规则把有序的序列映射掉,然后 ...
- uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)
这题数据大容易TLE 优化:预处理, 可以先枚举出5^3的状态然后判断合不合法,但是由于题目说了有很多墙壁,实际上没有那么多要转移的状态那么可以把底图抽出来,然后3个ghost在上面跑到时候就不必判断 ...
- Android开发出现 StackOverflowError
问题:StackOverflowError 在HTC或者摩托罗拉的手机上测试出现 StackOverflowError 的错误. 06-12 10:28:31.750: E/AndroidRuntim ...
- NSXMLParser
NSXMLParser的使用 2011-05-05 15:50:17| 分类: 解析|字号 订阅 NSXMLParser解析xml格式的数据 用法如下: 首先,NSXMLParser必须继续 ...
- iOS9适配总结
每年iOS升级,都会带来一些坑,这次iOS9也不例外.本文总结了微信在适配iOS9上遇到的问题和解决方案. 一.iOS9问题汇总 1. 编译问题(Bitcode) 大部分人升级到Xcode7后,首 ...
- 一些恶搞人的c++程序
top1: 不停打开的cmd(磁盘操作系统) 代码如下: #include<windows.h> using namespace std; int main() { system(&quo ...
- sql执行过长,如何入手优化
一条sql执行过长的时间,你如何优化,从哪些方面 1.查看sql是否涉及多表的联表或者子查询,如果有,看是否能进行业务拆分,相关字段冗余或者合并成临时表(业务和算法的优化)2.涉及链表的查询,是否能进 ...
- statistics-skewed data
参考文献: http://www.statisticshowto.com/skewed-distribution/ left/negatively-skewed distributions : box ...
- python数据类型之列表(list)和其常用方法
列表是python常用数据类型之一,是可变的,可由n = []创建,也可由n = list()创建,第一种方法更常用. 常用方法总结: # 创建方法 n = [] 或者 n = list() # in ...