I have asked this before and i have had a couple answers but no solution. could someone please help me understand what i need to do to fix this problem? My app force closes unless GPS in enabled BEFORE the app is started. I am learning how to program android and some answers I get I just dont not understand. Im hoping someone will point out which piece of code is causing the problem and what i need to do to fix it. If more information is needed, please let me know what you need. and seriously, **thanks for helping** and having patience with this 'beginner.' 

```
public class GlenrochieMain extends Activity
{
    //called when activity is first created
@Override
protected void onCreate(Bundle savedInstanceState) {
    // shows main layout
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //GPS Functionality

    LocationManager locationManager;
    String context = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(context);

    //Criteria for GPS
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    String provider = locationManager.getBestProvider(criteria, true);      

    Location location = locationManager.getLastKnownLocation(provider);
    updateWithNewLocation(location);

    //updates location every 5second+5meters
    locationManager.requestLocationUpdates(provider, 5000, 5,
            locationListener);
  }

private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      updateWithNewLocation(location);
    }

    public void onProviderDisabled(String provider){
      updateWithNewLocation(null);
    }

    public void onProviderEnabled(String provider){ }
    public void onStatusChanged(String provider, int status, 
                                Bundle extras){ }
  };

  private void updateWithNewLocation(Location location) {
    String latLongString;
    TextView myLocationText; 
    myLocationText = (TextView)findViewById(R.id.myLocationText);
    if (location != null) {
      double lat = location.getLatitude();
      double lng = location.getLongitude();
      latLongString = "Lat:" + lat + "\nLong:" + lng;
    } else {
      latLongString = "No location found"; 
    }
    myLocationText.setText("Your Current Position is:\n" + 
                           latLongString);
  }

}

```