在Activity中引入百度地图,第一次显示没问题,第二次回调onReceiveLocation(BDLocation bdLocation) 以下这句代码baiduMap.setMyLocationConfigeration(config);报空指针异常。错误日志如下:
12-13 14:24:52.511 21198-21198/com.baojiacg.bjfs E/ODBReader: java.lang.NullPointerException
at com.baidu.mapapi.map.BaiduMap.a(Unknown Source)
at com.baidu.mapapi.map.BaiduMap.setMyLocationConfigeration(Unknown Source)
at cn.bagechuxing.app.manage.activity.HavegotTaskActivity.onReceiveLocation(HavegotTaskActivity.java:321)
at com.baidu.location.LocationClient.k(Unknown Source)
at com.baidu.location.LocationClient.if(Unknown Source)
at com.baidu.location.LocationClient.if(Unknown Source)
at com.baidu.location.LocationClient$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5034)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.aurora_org_main(ZygoteInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
解决办法,在OnDestroy中增加代码mLocationClient.stop();即可,修改代码如下:
@Override
public voidonDestroy() {
super.onDestroy();
if(routePlanSearch!=null) {
routePlanSearch.destroy();
}
mLocationClient.stop();
if(mapView!=null) {
mapView.onDestroy();
}
if(handler!=null){
handler.removeCallbacksAndMessages(null);
}
}