Android (LocationManager)getSystemService(LOCATION_服务)返回null
我有一个服务,在它的onCreate()方法中,我尝试获取LocationManager类的实例Android (LocationManager)getSystemService(LOCATION_服务)返回null,android,service,locationmanager,Android,Service,Locationmanager,我有一个服务,在它的onCreate()方法中,我尝试获取LocationManager类的实例 LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 在我的活动中,我创建一个新的意图并启动服务 Intent t = new Intent(MainActivity.this, MyService.class); MainActivity.t
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
在我的活动中,我创建一个新的意图并启动服务
Intent t = new Intent(MainActivity.this, MyService.class);
MainActivity.this.startService(t);
只要我以以下方式在清单中注册服务,它就可以正常工作:
<service
android:name="de.path.MyService" />
现在启动服务时,我得到一个NullPointerException,告诉我LocationManager中的ILocationManager MSService为null
没有上下文吗?有办法获得系统服务吗?声明此-->private LocationManager locationMangaer=null;没用。仍然会得到相同的错误
android:process=":MyGPSProcess"