I wrote some code that sets a marker on a current location when clicked. Unfortunately, the entire application crashes when no current location is given and the button is clicked. The error states: java.lang.NullPointerException: Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference
Is there a way implement a try catch exemption within the button?
Here is the on click instruction for the button:
markerBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LatLng myCurrentLocation = new LatLng(myCurrentLatitude, myCurrentLongitude);
marker = mMap.addMarker(new MarkerOptions().position(myLocation).title("New Marker"));
markerBtn.setTag("yo");
}
});