Android app crashes when retrieving Last Known Location with Location Manager for GPS
<p>To be clear: This is an activity in my Android application that is meant to pull the coordinates for the users location using the GPS_PROVIDER. The Activity contains a button which, when pressed, should initiate a method that obtains the coordinate data. The problem is that the application crashes when there is no previously known location information (ie if the phone was recently reset). If I open up the Maps application (for example) and pinpoint my location, then re-open my own application and run this method, it works as intended. My question is why is this crashing and/or how can I prevent this crash from occurring? Help is appreciated, thanks.</p>

<p>This method is run when the button is pressed - and an intent response is generated back to the calling activity when the coordinates are properly found:</p>

<pre><code>protected void getCurrentLocation() {
    Location location = null;
    try {
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } catch (IllegalArgumentException iae) { }

    if (location != null) {
        longV = location.getLongitude();
        latV  = location.getLatitude();
        response(longV, latV);
    } else {
        getCurrentLocation();
    }
</code></pre>
