在我的應用程序中,我正在檢查GPS強度。我得到一個java.lang.IllegalArgumentException
:我的LocationListener在Android中爲null
listener==null.
我沒有指派代碼監聽器是空的,我寫的OnCreate()
方法的代碼。我不知道爲什麼聽者會變爲空。我哪裏錯了?
我的代碼:
public class Gps_strength extends Activity{
private LocationManager mLocationManager;
private LocationListener mGpsLocationListener;
private GpsStatus.Listener gps_listener;
public void onCreate(Bundle savedInstanceState) {
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mGpsLocationListener); // line no 31.
mLocationManager.addGpsStatusListener(gps_listener);
if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) == true) {
..... GPS strength checking coding..
}
}
}
的logcat:
06-03 13:04:30.695: ERROR/AndroidRuntime(2595): Caused by: java.lang.IllegalArgumentException: listener==null
06-03 13:04:30.695: ERROR/AndroidRuntime(2595): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:627)
06-03 13:04:30.695: ERROR/AndroidRuntime(2595): at com.gps.Gps_strength.onCreate(Gps_strength.java:31)
如何設置mGpsLocationListener的有效值而不是null – 2011-06-03 09:39:45
更新了原始評論。 – 2011-06-03 10:15:03
Murali你經歷了我已經回覆給你的網址 – 2011-06-03 10:22:37