Android java.lang.RuntimeException: Can\'t create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:农村淘宝加盟官方网站 编辑:程序博客网 时间:2024/05/31 19:11
E/AndroidRuntime(7200): Uncaught handler: thread Thread-8 exiting due to uncaught exception
E/AndroidRuntime( 7200): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
原因是非主线程中默认没有创建Looper对象,需要先调用Looper.prepare()启用Looper。
解决办法:
public void sendJson2Server(final JSONObject mJs) { Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); PushServiceEx.sendPublic(mTopicServer, mJs.toString()); System.out.println(mJs.toString()); } }; mHandler.sendEmptyMessageDelayed(0, 5000); //PushServiceEx.sendPublic(mTopicServer, mJs.toString()); }
new Thread() {
public void run() {
Looper.prepare();
mPst.startPushService();
mPst.sendJson2Server(qJson);//上线发消息给server
Looper.loop();
}
}.start();
加上上面红色两行。
- Android java.lang.RuntimeException: Can\'t create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- java.lang.RuntimeException: 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
- Android 判断一个Service是否已经运行
- Android 点击back键两次退出程序
- iOS 获取 顶层控制器
- Android 防止Service被系统回收
- Android:adb 启动activity、service,发送broadcast
- Android java.lang.RuntimeException: Can\'t create handler inside thread that has not called Looper.prepare()
- Android:monkey测试工具
- js——DOM操作
- android:根据下载文件的url获取文件名
- android:从ArrayList<HashMap<String, Object>>中获取键值对
- Android:判断某一个service是否已经在运行
- 短url的意义和实现(类似微博短url)
- android:app接收adb发送的命令并显示
- Android:apk签名