• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps LocationListener throws NullPointerException in Emulator

neolyth

Lurker
I'm new to android, just read a book about it and now I go step by step through sample codes.

I work with Eclipse (Kepler Service Release 2) and an avd in the emulator(Nexus 5 with Android 4.4.2) and I try to run a simple code which displays gps coordinates in textView fields. I set them by telnetting to the emulator and use geo fix. This works fine. But I also have a LocationListener which throws a NullPointerException. So I first start the emulator, then I set the coordinates with geo fix, then I load the app in the emulator and the coordinates are shown on screen. When I then change the coordinates again with geo fix while the app is still running, I get this error. Whats the problem? Do I need to configure anything in the emulator to have the Location Listener work probperly? Below my code strongly reduced and the LogCat error message.

Code:
...
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location loc = lm.getLastKnownLocation(
 
Back
Top Bottom