In my app I am checking GPS strength. I get an java.lang.IllegalArgumentException
:
listener==null.
I did not assign code listener to be null, and I write the code in the OnCreate()
method. I don't know why listener turns null. Where am I going wrong?
My code:
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)