Nullpointer exception with location manager
<p>I wrote the below code for getting lat long positions</p>

<pre><code> myLocationManager = (LocationManager)getSystemService    
  (Context.LOCATION_SERVICE);
                  myLocationListener = new MyLocationListener();

          myLocationManager.requestLocationUpdates
  (LocationManager.GPS_PROVIDER, 1, 1, myLocationListener);

  //HERE UNCOMMENT
   latitude=myLocationManager.getLastKnownLocation
  (LocationManager.GPS_PROVIDER).getLatitude();
   longitude=myLocationManager.getLastKnownLocation
         (LocationManager.GPS_PROVIDER).getLongitude();
</code></pre>

<p>I am getting Nullpointer exception at the following line<br>
     (LocationManager.GPS_PROVIDER).getLatitude();</p>

<p>I am testing the code on my Android 2.1 phone with GPS enabled and I gave the following permissions in the manifest file</p>

<pre><code>android.permission.ACCESS_FINE_LOCATION  
android.permission.ACCESS_COARSE_LOCATION  
android.permission.INTERNET  
android.permission.ACCESS_WIFI_STATE  
android.permission.ACCESS_NETWORK_STATE  
android.permission.VIBRATE  
</code></pre>
