Android-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()
当我们在一个新的线程中使用android UI时,遇到这个异常
看了很多文章也还是不太清楚具体是什么原因,但是处理这个问题是很简单的,如下代码:
|
1
2
3
4
5
6
7
8
9
10
11
|
@Overridepublic void run() { //前面代码省略 Looper.prepare(); Log.i("---my tag---", "下载完成:"+downloadPath); Toast.makeText(context, fileName+"下载完成...", Toast.LENGTH_LONG).show(); Looper.loop(); } |
在使用Toast之前加一行Looper.prepare();,然后在Toast之后加一行Looper.loop();,即可实现。看了很多文章也没理解,所以这里就不误导大家了,感兴趣的自己搜搜原因。
上面代码是我自己写的文件下载功能一部分代码,完整代码可以查看:
Android-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()的更多相关文章
- 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.pre ...
- 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只能在UI线程弹出,解决此问题可以在Toast前后加两行代码,如下所示: Looper.prepare(); Toast.makeText(getApplicationContext(),& ...
- 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 ...
- 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 ...
- 在子线程中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 ...
- 转 在子线程中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 ...
随机推荐
- OQL对象查询语言
在用mat工具分析内存使用情况查询OutOfMemory原因时,OQL会有很大帮助,所以先在这里总结一下. 基本语法: select <javascript expression to sele ...
- JVM垃圾回收日志结构分析
我们在我们Server的gc log上经常看到下面的这个日志: 总结一下各个字段表达的是什么意思: Young GC Full GC: top -H -P $PID 动态查看java线程的消耗情况 ...
- Ubuntu lnmp安装记录
参考了: Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL 在访问 info.php的时候,我显示的是502错误.后面我参考了: Ubuntu15 ...
- .NET学习笔记(2) — IIS服务器环境搭建
目录 一:开启Windows系统自带的IIS服务器方法 二:备注 三:常见问题 一:开启Windows系统自带的IIS服务器方法 第一步:安装IIS,控制面板->程序和功能-> ...
- 倒影(box-reflect)
box-reflect: 语法:box-reflect:none | <direction> <offset>? <mask-box-image>?因为不是w3c标 ...
- ServletContext中的转发
客户端向服务器发送请求,服务器将请求进行转发,获得响应信息,客户端只发送一次请求,地址栏信息不变. 服务器接收类,进行转发 package com.itheima.zhuanfa; import ja ...
- JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
An enum type is annotated with XmlEnum. It has an optional element value of type java.lang.Class whi ...
- python出现Non-ASCII character '\xe7' in file ex6.py on line 1, but no encoding declare错误
http://www.cnblogs.com/qi09/archive/2012/02/06/2340712.html python中出现Non-ASCII character '\xe7' in f ...
- html-----020----事件
html事件 <body> <a href="http://www.cctv.com" accesskey="k" target=" ...
- java包和jar包
1.包 package pack; /*定义包,放在程序的第一行,包名所以字母小写*/ class PackageDemo{ publi ...