title: Is this error the reason my code always returns "no location"?
body: <p>I am making an app that will require the user's location.  This is its code so far:</p>
  
  <pre><code>import android.Manifest;
  import android.app.Activity;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.location.Criteria;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Build;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  
  public class MainActivity extends Activity implements LocationListener {
  
  LocationManager locationManager;
  String provider;
  Location location;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
      provider = LocationManager.NETWORK_PROVIDER;
  
  
      location = locationManager.getLastKnownLocation(provider);
  
  
  }
  
  public void locationStuff(View view) {
      if (location != null) {
  
          Log.i("Location Info", "Location achieved!");
  
      } else {
  
          Log.i("Location Info", "No location :(");
  
      }
  
  }
  
  
  @Override
  protected void onResume() {
      super.onResume();
  
  
      locationManager.requestLocationUpdates(provider, 400, 1, this);
  
  }
  
  
  @Override
  protected void onPause() {
      super.onPause();
  
  
      locationManager.removeUpdates(this);
  
  }
  
  @Override
  public void onLocationChanged(Location location) {
  
      Double lat = location.getLatitude();
      Double lng = location.getLongitude();
  
      Log.i("Location info: Lat", lat.toString());
      Log.i("Location info: Lng", lng.toString());
  
  }
  
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
  
  }
  
  @Override
  public void onProviderEnabled(String provider) {
  
  }
  
  @Override
  public void onProviderDisabled(String provider) {
  
  }
  
  
  public void getLocation(View view) {
  
      Location location = locationManager.getLastKnownLocation(provider);
  
      onLocationChanged(location);
  
  
  }
  
  }
  </code></pre>
  
  <p>It only returns " no location".  I am trying to get it to output "location achieved".  I attached a link to a picture of the error.  Please let me know if you see what is wrong.<a href="http://i.stack.imgur.com/v9fak.png" rel="nofollow">error image</a></p>