您的位置:首页 > 编程语言 > Java开发

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同一线程中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java.lang.RuntimeExc