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.
This commit is contained in:
Jason Whitmore 2024-07-06 16:17:24 -07:00
parent efe6eb27ed
commit caed893d23

View file

@ -400,19 +400,21 @@ 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);
}
if(position != null){
Utils.handleGeoCoordinates(this, position);
}
}
/**
* Moves the center of the map to the media's location (likely EXIF data), if that data