title: Android Location Object Always Null
body: <p>I'm simply trying to write a method that returns Latitude and Longitude. I have an activity with a button and two text fields. The java class I am using extends <code>AppCompatActivity</code> and implements <code>LocationListener</code> When the button is pressed the following method is pressed:</p>
  
  <pre><code>public void startGPS(View view)
  {
  
          // Here is the code to handle permissions - you should not need to edit this.
          if ( Build.VERSION.SDK_INT &gt;= 23 &amp;&amp;
                  ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED &amp;&amp;
                  ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION }, TAKE_PHOTO_PERMISSION);
          }
  
          Location location = locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, this);
  }
  </code></pre>
  
  <p>Later on I try to print out my location in my <code>onLocationChanged</code> method but it was causing the app to crash. I ran it through the debugger and found that the location was always <code>null</code>.</p>
  
  <p>I tried to <a href="https://stackoverflow.com/questions/11755921/location-returns-always-null-android">this solution</a> but it didn't work. Other examples are calling the function in <code>onResume</code> but I really need this to be in <code>startGPS</code> method.</p>
  
  <p>Also, is there a chance that the error is just with my device? I'm running it on a Nexus 7 which doesn't seem to have any problems when I run Google Maps.</p>