首页 > 移动平台 > 详细

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

时间:2014-07-24 22:12:02      阅读:342      评论:0      收藏:0      [点我收藏+]

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(),布布扣,bubuko.com

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

原文:http://www.cnblogs.com/antyi/p/3866141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!