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

来源:互联网 发布:php取字符串的某个值 编辑:程序博客网 时间:2024/06/05 21:13

1.问题现象

       运行程序时,进行某个操作后,程序异常终止并退出,出现一个“很抱歉,XXX已停止运行”的提示,查看"LogCat"发现在红色字体显示的错误行中有一行是:“java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()”

2.解决方案

        出现这个问题的原因是因为:把UI的处理操作放到了线程中,如Timer或者Thread的run()方法中处理。如下图

 

           解决的方法就是将UI的操作放到Handler中去处理。

0 0
原创粉丝点击