the code below gives a NullPointerException is there any other way of getting current location in android application
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) {} public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE) locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); double latitude = location.getLatitude(); //NullPointerException double longitude = location.getLongitude();