Can't create handler inside thread that has not called Looper.prepare()
@迷途d书童 你好,想跟你请教个问题:
OSCHINA Android 客户端中用到Thread和Handler很正常,为什么我用就有异常呢?异常提示是
10-31 11:12:12.344: V/crashReport(7106): Exception: Can't create handler inside thread that has not called Looper.prepare()
private void refreshTaxi(Drawable marker) { final Handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == -1 && msg.obj != null) { ((AppException) msg.obj).makeToast(MainActivity.this); } } }; final OverItemT oit = new OverItemT(marker, this); new Thread() { public void run() { Message msg = new Message(); // 获取出租车列表 RequestData rd = new RequestData(); RequestResult<List<Taxi>> r; try { r = rd.fetchTaxi(null, null); if (RequestResult.Success == r.resultCode) { List<Taxi> taxiList = r.data; oit.addOverItem(taxiList); mMapView.getOverlays().add(oit); // 添加ItemizedOverlay实例到mMapView } else { Toast.makeText(MainActivity.this, "服务器开小差,不能获取出租车信息", Toast.LENGTH_SHORT).show(); } } catch (AppException e) { e.printStackTrace(); msg.what = -1; msg.obj = e; handler.sendMessage(msg); } }; }.start(); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么解决的??