Android java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pr
来源:互联网 发布:数控g94编程实例带图 编辑:程序博客网 时间:2024/06/07 02:25
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.pr
- Android java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pr
- android java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pr
- android java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pr
- Android 异常 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper
- 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()
- CDN原理
- 王立平--TF卡
- openfiler作为文件服务器,实现ISCSI共享存储
- poj 1182 食物链
- SDL2.0_08_timer
- Android java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.pr
- int _tmain(int argc, _TCHAR* argv[])
- 线程池ThreadPoolExecutor参数设置
- UVa 11428 - Cubes
- Android回调机制(全面深入学习)
- 快速输入java系统用户名和密码
- poj 2154 polya定理+数论知识
- js 控制 Windows Media Player播放列表
- 你会喝汤吗?喝汤八大注意