【发布时间】:2014-01-24 11:26:05
【问题描述】:
我收到一个错误,好像找不到我正在使用的 LocationService 我错过了什么?
这是我的清单:
<activity
android:name="com.example.manyexampleapp.StoresListActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="com.example.manyexampleapp.LocationService" />
我的 StoresListActivity 类:
package com.example.manyexampleapp;
public class StoresListActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LocationService locService = new LocationService();
locService.startService(new Intent());
}
我的 LocationService 类
package com.example.manyexampleapp;
public class LocationService extends Service {
public static final String LOCATION_BROAD_MSG = "Hello World";
private static final int TWO_MINUTES = 1000 * 60 * 2;
public LocationManager locationManager;
public MyLocationListener listener;
public Location previousBestLocation = null;
Intent intent;
int counter = 0;
@Override
public void onCreate() {
super.onCreate();
intent = new Intent(LOCATION_BROAD_MSG);
}
@Override
public void onStart(Intent intent, int startId) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
listener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 4000, 0, listener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, listener);
}
【问题讨论】:
标签: java android android-intent nullpointerexception android-manifest