我想SENSOR_ACCELEROMETER
在服务中注册一个,但结果是一个空异常。以下是我的代码:
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)
我不知道问题是什么,sensoreventlistener 的实例不是 null::::com.wogua.mobileprotected.sensor.AccerSensor@41bf3f20
这怎么可能是 null,:::manager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);