java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
2015-11-17 20:16
841 查看
在开发游戏/应用的过程中,如果出现:java.lang.RuntimeException: Can't create handler inside threadthat has not called
Looper.prepare()
这种报错,可以查看log知道,大概的原因是因为在你的这个线程中调用了其与其余线程中的activity
解决方法:
需要这同样的线程中调用只需要创建一个handler
Handler handler = new Handler();
Runnable EnentRun = new Runnable()
{
public void run()
{
//做你需要的事情......
handler.removeCallbacks(this);
}
}
handler.post(EnentRun);
这样就可以使其在activity同一线程中
Looper.prepare()
这种报错,可以查看log知道,大概的原因是因为在你的这个线程中调用了其与其余线程中的activity
解决方法:
需要这同样的线程中调用只需要创建一个handler
Handler handler = new Handler();
Runnable EnentRun = new Runnable()
{
public void run()
{
//做你需要的事情......
handler.removeCallbacks(this);
}
}
handler.post(EnentRun);
这样就可以使其在activity同一线程中
相关文章推荐
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- 解决-LogCat:Binary XML file line # : Error inflating class fragment
- 在线程里面出现异常需要处理UI的细节
- java.lang.RuntimeException: eglCreateContext,failed:EGL_BAD_ALLOC
- java.lang.RuntimeException: Value <pre>bool(false) of type java.lang.String cannot be converted to J
- java.lang.RuntimeException: Unable to destroy activity
- java.lang.RuntimeException: invoke method
- java.lang.RuntimeException: Unable to instantiate application
- java.lang.RuntimeException: Unable to destroy activity
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- 静态注册Fragemnt
- java.lang.RuntimeException
- myeclipse10 svn: E175002 svn:unable to connect to a repository at URL
- java继承&子父类成员域加载及执行过程
- Java 文件监控,实时监控文件加载
- 使用WebMagic爬新浪博客
- 第12周-Swing通用特性-六个色彩标签的框架
- 无法载入共享目标对象‘...rJava.dll’
- 【Struts】服务器文件的上传和下载
- JavaWeb开发基础:JDBC