I wrote the below code for getting lat long positions
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();
I am getting Nullpointer exception at the following line
(LocationManager.GPS_PROVIDER).getLatitude();
I am testing the code on my Android 2.1 phone with GPS enabled and I gave the following permissions in the manifest file
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
Did you send coordinates from DDMS? If not. Do it then envoke request for location updates, I’m sure that 99.9% you wont get NPE again for this.