代码改变世界

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()解决办法的更多相关文章

  1. java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

  2. 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 ...

  3. android Toast提示异常:java.lang.RuntimeException: Can't create handler inside thread that has not called

    Toast只能在UI线程弹出,解决此问题可以在Toast前后加两行代码,如下所示: Looper.prepare(); Toast.makeText(getApplicationContext(),& ...

  4. 在子线程中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 ...

  5. 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 ...

  6. Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()

    问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 // handler监听网络请求,完成后操作回调函数 final Handler trigerGfHandler ...

  7. 【转】在子线程中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 ...

  8. 转 在子线程中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 ...

  9. 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 ...

随机推荐

  1. Windows7(x86) xampp php5.5 imagick install

    I hate windows. 1. 下载安装 ImageMagick, 选择合适您电脑的版本,我下载的是: ImageMagick-6.8.9-1-Q16-x86-dll.exe http://ww ...

  2. 洛谷 P1784 数独

    题目描述 数独是根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行.每一列.每一个粗线宫内的数字均含1-9,不重复.每一道合格的数独谜题都有且仅有唯一答案,推理方法也以此为基础,任何无 ...

  3. 唱吧APP产品体验报告

  4. ansible-galera集群部署

    一.环境准备 1.各主机配置静态域名解析: [root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain local ...

  5. SpringMVC-常用的注解

    1. RequestParam注解 把请求中的指定名称的参数传递给控制器中的形参赋值 value:请求参数中的名称 require:请求参数中是否必须提供此参数,默认值是true,必须提供 2. Re ...

  6. XPath语法规则及实例

    XPath语法规则及实例 XPath语法规则 一.XPath术语: 1.节点:在XPath中,有七种类型的节点:元素.属性.文本.命名空间.处理指令.注释以及文档(根)节点. XML文档是被作为节点树 ...

  7. 使用MaskedTextBox控件实现输入验证

    实现效果: 知识运用: MaskedTextBox控件的 Mask属性 BeepOnError属性 MaskInputRejected事件 实现代码: private void Form1_Load( ...

  8. Python面向对象(三)

    类的使用:实例化.属性引用 实例化 g1 = Garen('草丛伦1') # 实例化 g2 = Garen('草丛伦2') g3 = Garen('草丛伦3') 类的属性:变量和函数 print(Ga ...

  9. OC和C++的混用2

    苹果的Objective-C编译器允许用户在同一个源文件里自由地混合使用C++和Objective-C,混编后的语言叫Objective-C++.有了它,你就可以在Objective-C应用程序中使用 ...

  10. win8/10 bcdboot引导修复命令的原理和使用方法

    win8/10 bcdboot引导修复命令的原理和使用方法 [迅维网原创文章禁止转载] (本文所述已用UEFI+GPT.BIOS+MBR,WIN10 64位企业版和专业版测试过) 在win8/10系统 ...