我通过 crashlytics 从用户体验中得到一些报告,给我一个错误
Fatal Exception java.lang.NullPointerException
CameraUpdateFactory is not initialized
这不是常规崩溃,因为它不会发生在每个用户身上,但它变得太常规了,我需要解决它。
我读过如果我认为我已经涵盖的地图没有被初始化,这可能会发生
if(googleMap!=null){
googleMap.animateCamera(CameraUpdateFactory.newLatLng(selectedLatLng));
}
还有一个可能的原因可能是设备上没有谷歌播放服务或已过时,我也为此添加了一些验证。
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(FuelsFragment.this.getActivity());
// Showing status
//CAMERAUPDATE FACTORY CRASH CAN BE A RESULT OF GOOGLE PLAY SERVICES NOT INSTALLED OR OUT OF DATE
//ADDITIONAL VERIFICATION ADDED TO PREVENT FURTHER CRASHES
//https://github.com/imhotep/MapKit/pull/17
if(status == ConnectionResult.SUCCESS)
{
mMapFragment = ReepMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.mapContainer, mMapFragment);
fragmentTransaction.commit();
}
else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
reep.toastNotify("You need to update Google Play Services in order to view maps");
}
else if (status==ConnectionResult.SERVICE_MISSING){
reep.toastNotify("Google Play service is not enabled on this device.");
}
在那之后,我不确定接下来要做什么,因为这不会发生在每个用户身上。
如果有人对为什么会发生这种情况有任何想法,我将不胜感激您的意见