studio 异常Can't create handler inside thread that has not called Looper.prepare()

原创 2016年08月29日 00:08:49
错误信息:在Android开发中,如果在一个Thread中启动了一个ProgressDialog用来提示正在连接(也就是防假死),然后在Handler中dismiss()这个ProgressDialog,程序就直接挂掉,异常信息是:Can't create handler inside thread that has not called Looper.prepare()

原因分析:本人遇到的情况是在程序刚开始时候调用ProgressDialog提示正在连接(防假死调用),后边在连接成功后dismiss()这个ProgressDialog,如果有错误信息(比如连接失败呀什么的)则在线程中调用Toast提示,然后当程序运行到Toast的地方的时候程序就直接挂掉了

解决方法:在调用Toast(或者AlertDialog)的地方的前面加上Looper.prepare(),后边加上Looper.loop()即可解决问题;也就是说用Looper.prepare()和Looper.loop()把Toast前后包起来。

相关文章推荐

解决bug:运行项目时报异常 “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()” 问题描述:在Android Studio...

解决异常Can't create handler inside thread that has not called Looper.prepare()方法

最近做项目时出现个问题。 在一个基类中,创建一个Handler对象用于主线程向子线程发送数据,代码如下...

记录一次因为Android版本不同导致的crash异常:Can't create handler inside thread that has not called Looper.prepare()

Can't create handler inside thread that has not called Looper.prepare() 版权声明:本文为博主原创文章,未经博主允许不得转载。该异...
  • wwcxq
  • wwcxq
  • 2017年02月24日 13:54
  • 140

Android蓝牙开发,报BluetoothAdapter﹕ Can't create handler inside thread that has not called Looper.prepare

这个错误翻译的意思是:不能在没有Looper.prepare的线程里面创建handler。起初我很疑惑,我根本没有用到工作线程,也没有创建handler。报错的代码如下: // Device s...

Android进阶(十六)子线程调用Toast报Can't create handler inside thread that has not called Looper.prepare() 错误

原子线程调用Toast报Can't create handler inside thread that has not called Looper.prepare() 错误 今天用子线程调Toast报...

错误解决 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不能在线程里面更新UI...

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

在解决这个问题时,觉得以下比较有用 为了正确的使用AsyncTask类,以下是几条必须遵守的准则:   1) Task的实例必须在UI thread中创建   2) execute方法必须在...

报错“Can't create handler inside thread that has not called Looper.prepare()” 的处理方法

如果在编译的时候出现这样的报错:Can't create handler inside thread that has not called Looper.prepare(),是因为新new的线程中出...

Can't create handler inside thread that has not called Looper.prepare()解决办法

private Handler mHandler = new Handler(){ public void handleMessage(Messa...
  • a7a9a68
  • a7a9a68
  • 2012年08月08日 09:31
  • 48546

错误: Can't create handler inside thread that has not called Looper.prepare()

最近做项目时出现个问题。 在一个基类中,创建一个Handler对象用于主线程向子线程发送数据,代码如下 1 this.mThirdHandler = new Handler...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:studio 异常Can't create handler inside thread that has not called Looper.prepare()
举报原因:
原因补充:

(最多只允许输入30个字)