(android)Can't Create handler inside thread that has not called Looper.prepare()

接android游戏sdk中,经常会遇到Looper报错,此时需要在主线程中调用sdk函数。

将sdk的函数放到UI线程中执行。

如:

activity.runOnUiThread(new Runnable() {

@Override

public void run() {

}

});

(android)Can't Create handler inside thread that has not called Looper.prepare()

时间: 2024-11-03 22:11:34

(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()

又报错了,不过早也习以为常了. Can't create handler inside thread that has not called Looper.prepare() 我把文档给摘录下来了,大家可以看看. 这个类被用于为线程运行消息循环.默认线程并没有消息循环与之关联,所以你需要创建一个,在线程中调用prepare()以运行这个循环,然后调用loop()在循环结束时获取进程信息. 和消息循环交互最多的就是通过Handler类. 下面是一个实现了Looper线程的典型实例,通过分离的pre

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().toString(); String timelength = lengthText.getText().toString(); ExecutorService exec = Executors.newCachedThreadPool(); exec.execute(new NewsService(getApp

Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()

解决方法,在ui线程里面创建handler m_MainActivity.runOnUiThread(new Runnable(){ @Override public void run() { // TODO Auto-generated method stub GameBoxUtil.startPay(m_MainActivity,String.valueOf(amount), productName, payCode,orderId,payHandler); }}); Android han

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

E/AndroidRuntime(7200): Uncaught handler: thread Thread-8 exiting due to uncaught exceptionE/AndroidRuntime( 7200): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 原因是非主线程中默认没有创建Looper对象,需要先调用Looper

Android蓝牙开发,报BluetoothAdapter﹕ Can't create handler inside thread that has not called Looper.prepare

这个错误翻译的意思是:不能在没有Looper.prepare的线程里面创建handler. 起初我很疑惑,我根本没有用到工作线程,也没有创建handler.报错的代码如下: // Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(final Blu

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/AndroidRuntime(28343): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 10-12 17:02:55.500: E/AndroidRuntim

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

1. 程序时,出现运行时异常,如上图所示. 2.异常原因分析.在ContentObserver的onChange方法中,调用了Toast.makeText方法.onChange方法应该在子线程运行,在android中的子线程中不能直接控制UI组件,否则就会报异常 3.Looper类别用来为一个线程开启一个消息循环.默认情况下Android中新诞生的线程是没有开启消息循环的.(主线程除外,主线程系统会自动为其创建Looper对象,开启消息循环) java.lang.RuntimeException

Can’t create handler inside thread that has not called Looper.prepare()

1)在Android 2.3以前,为防止ANR(Application Not Responding),Google是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程内:而Android 4.0版本开始,Google强制要求这类操作必须在子线程内进行,否则将抛出 NetworkOnMainThreadException 异常. (2)操作UI必须只能在主线程内进行,否则报“Can’t create handler inside thread that has n

转 在子线程中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 not called Looper.prepare()  这是因为Handler对象与其调用者在同一线程中,如果在Handler中设置了延时操作,则调用线程也会堵塞.每个Handler对象都会绑定一个Looper对象,每个Looper对象对应一个消息队列(MessageQueue).如果在创建Ha