From caed893d23f8109bd301a5fb66851010f526ab6d Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Sat, 6 Jul 2024 16:17:24 -0700 Subject: [PATCH] LocationPickerActivity.java: add null checks to showInMapApp Before this change, there was no null checks when accessing data from an object, which could create null pointer exceptions at runtime. After this change, null checks are introduced to make sure null pointer exceptions will not occur. --- .../commons/LocationPicker/LocationPickerActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java index 80ca67c13..81cf73ac3 100644 --- a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java @@ -400,18 +400,20 @@ public class LocationPickerActivity extends BaseActivity implements * If there is no EXIF data, the map will center on the commons app map center. */ private void showInMapApp() { - fr.free.nrw.commons.location.LatLng position = null; + //Check to see if EXIF location data is available - if(activity.equals("UploadActivity")){ + if(activity.equals("UploadActivity") && cameraPosition != null){ position = new fr.free.nrw.commons.location.LatLng(cameraPosition.getLatitude(), cameraPosition.getLongitude(), 0.0f); - } else { + } else if(mapView != null){ position = new fr.free.nrw.commons.location.LatLng(mapView.getMapCenter().getLatitude(), mapView.getMapCenter().getLongitude(), 0.0f); } - Utils.handleGeoCoordinates(this, position); + if(position != null){ + Utils.handleGeoCoordinates(this, position); + } } /**