android -- Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:钻戒哪个牌子好 知乎 编辑:程序博客网 时间:2024/06/10 08:12
第一次遇见这个问题:
Can’t create handler inside thread that has not called Looper.prepare()
百度翻译下:
无法创建程序的线程没有调用prepare()活套。
//什么乱七八糟的。。。。
我的报错的程序是这样的:
1、主MainActivity:
主要目的:主程序开启后3s,调用对时方法
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread(new Runnable(){ @Override public void run() { try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Select_Http sh=new Select_Http(); sh.getTime_Http();//校对服务器时间 } }).start(); }
2、Select_Http类:
public void getTime_Http(){ sh=new SyncHttp(); new Thread(new Runnable(){ @Override public void run() { System.out.println("获取时间"); String response=""; try { response=sh.httpGet(Url_GetTime, ""); Message message = new Message(); Bundle bundle = new Bundle(); bundle.putString("msg", response); message.setData(bundle); handler_time.sendMessage(message);//错误在这里;因为这样就调用到主程序啦 } catch (Exception e) { e.printStackTrace(); } } }).start(); } ```3、handler_time
private Handler handler_time = new Handler() {
public void handleMessage(Message msg) { //处理数据。。。。 }; };
修改下3、handler_time
private Handler handler_time = new Handler(MainActivity.mainActvity.getMainLooper()) {
}
“`
加上这个(MainActivity.mainActvity.getMainLooper())
0 0
- Unity-Android: Can't create handler inside thread that has not called Looper.prepare()
- Android 错误提示: Can't create handler inside thread that has not called Looper.prepare()
- android之Can't create handler inside thread that has not called Looper.prepare()
- android can't create handler inside thread that has not called Looper.prepare()解决方案
- [Android]Can't create handler inside thread that has not called Looper.prepare()
- Android 报Can't create handler inside thread that has not called Looper.prepare()错误!
- Android中的Can't create handler inside thread that has not called Looper.prepare()异常
- Android进阶(八)Can't create handler inside thread that has not called Looper.prepare()
- Android : Can't create handler inside thread that has not called Looper.prepare() 异常
- android -- Can't create handler inside thread that has not called Looper.prepare()
- Android : Can't create handler inside thread that has not called Looper.prepare()
- Android开发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异常收集-Can't create handler inside thread that has not called Looper.prepare()
- Android开发报错 Can't create handler inside thread that has not called Looper.prepare()
- Android开发报Can't create handler inside thread that has not called Looper.prepare()错误
- Android开发报错 Can't create handler inside thread that has not called Looper.prepare()
- Android未调用Looper.prepare()-Can't create handler inside thread that has not called Looper.prepare()
- 5.33Java 三星题 current date and time
- Java中Synchronized的用法
- apk隐藏到图片中
- Git 基础
- 2015年imac一体机安装双系统问题及解决技巧
- android -- Can't create handler inside thread that has not called Looper.prepare()
- CABasicAnimation用法
- createDialog
- hive的启动
- 可以实现pdf转换成txt格式的方法
- android数据库支持的数据类型
- Linux进程和内核级进程的一些知识
- windows 命令行查找字符串 和 文件(find & findstr & for)
- GitHub最火的Android开源项目