title: location.getLatitude() throws NullPointerException android
body: <p>I'm trying to get the current latitude and longitude coordinates. </p>
  
  <p><strong>my code</strong></p>
  
  <pre><code>    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  
      Criteria criteria = new Criteria();
      criteria.setAccuracy(Criteria.ACCURACY_LOW);
      String bestProvider = locationManager.getBestProvider(criteria, true);
      Location location = locationManager.getLastKnownLocation(bestProvider);
  
      if (location != null) {
          onLocationChanged(location);
      }
      locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);
  
      double latitude = location.getLatitude();
      double longitude = location.getLongitude();
  </code></pre>
  
  <p><strong>error message</strong> </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{conic.com.restaurant/conic.com.restaurant.MainActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
              at android.os.Handler.dispatchMessage(Handler.java:110)
              at android.os.Looper.loop(Looper.java:193)
              at android.app.ActivityThread.main(ActivityThread.java:5292)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at conic.com.restaurant.MainActivity.displayListView(MainActivity.java:121)
              at conic.com.restaurant.MainActivity.onCreate(MainActivity.java:50)
              at android.app.Activity.performCreate(Activity.java:5264)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
              at android.os.Handler.dispatchMessage(Handler.java:110)
              at android.os.Looper.loop(Looper.java:193)
              at android.app.ActivityThread.main(ActivityThread.java:5292)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here are the manifest declarations
  <strong>manifest declarations</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  </code></pre>
  
  <blockquote>
    <p>double latitude = location.getLatitude(); is in line number 121</p>
  </blockquote>
  
  <p>Hope you can help me.</p>