NullpointerException when calling getSystemService(Context.LOCATION_SERVICE) and onLocationChanged not called
问题 I am trying to create a background service that updates the current gps position. I am getting a NullPointerException at line LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); HomeActivity launches a service startService(new Intent(getApplicationContext(), ForHire.class)); Service (ForHire) creates a TimerTask Updates public class ForHire extends Service { ... private Timer getUpdatesNow = new Timer(); private Updates updates = new Updates(getUpdatesNow);