Once Popup Places was released two bugs which resulted in a crash became apparent:
1. java.lang.NullPointerException in ie.appz.popupplaces.PopupTrigger.onDestroy when Disable Notifications was toggled repeatedly.
This was caused by the line:
mNotificationManager.cancelAll();
Which was placed in the OnDestroy to close any open Notifications when the service which provided them was disabled by the user. Unfortunately this Notification Manager is only initialized when it is going to be used, so if no Notifications had been launched it was Null, calling a command on it would fail. To get around this I simply added a test to make sure that it was not null before calling the command:
if (mNotificationManager != null) { mNotificationManager.cancelAll(); }
2. java.lang.NullPointerException in ie.appz.popupplaces.ReminderMap_Activity.onCreate when Popup Places was run for the first time on some devices.
This was caused by the line:
GeoPoint oldGeo = new GeoPoint((int) (locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLatitude() * 1E6), (int) (locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLongitude() * 1E6));
Which was placed in onCreate to quickly determine the users location from their location history and then center the map on that point.
I had previously encountered a NullPointerException here, so oldGeo was already tested to make sure it wasn’t null before running any commands on it:
if (oldGeo != null) { mapView.getController().animateTo(oldGeo); mapView.getController().setZoom(18); }
What I didn’t realise when I wrote that was that the Null value was locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) and the exception was caused by running .getLatitude() and .getLongitude() on it.
To resolve this I put the code which was causing the error into a try and wrote a different method for determining the user’s location into the catch statement:
try { oldGeo = new GeoPoint((int) (locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLatitude() * 1E6), (int) (locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLongitude() * 1E6)); mapView.getController().animateTo(oldGeo); } catch (NullPointerException e) { Log.e(this.getClass().getName(), "No valid previous location, requesting a single location update instead."); Toast.makeText(this, "No valid previous location, requesting a single location update instead.", Toast.LENGTH_LONG).show(); Criteria mCriteria = new Criteria(); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mCriteria.setAccuracy(Criteria.ACCURACY_COARSE); } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mCriteria.setAccuracy(Criteria.ACCURACY_FINE); } mCriteria.setCostAllowed(false); locationManager.requestSingleUpdate(mCriteria, mListener, null); }
I could not find anyway to recreate the conditions which caused this problem so I put in a Toast Message hoping that users encountering this issue would know and hopefully get in touch with me.
I have pushed the fixed version to the Play Store and it should turn up in the next few hours.
Thanks for reading!
-Rory