I want to register a SENSOR_ACCELEROMETER
in a service, but it turns out to be a nullexception.Following is my code:
asensor = new AccerSensor(context);//the sensoreventlistener
Log.i("wogua", "creating"+asensor.toString());
manager.registerListener(asensor,manager.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
Exception:
Caused by: java.lang.NullPointerException::
at com.wogua.mobileprotected.service.LostProtectService.onCreate(LostProtectService.java:36)
I dont know what the problem is , the instance of the sensoreventlistener is not null::::com.wogua.mobileprotected.sensor.AccerSensor@41bf3f20
how could this to be null,:::manager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);