我已经创建了与zigbee设备进行通信的系统服务。更新了API并创建了system.img并在设备上闪现,并为android编程制作了自定义SDK。定制系统服务的上下文错误
在MainActivity类,
try {
ZigbeeManager zm = (ZigbeeManager) getSystemService(Context.ZIGBEE_SERVICE);
zm.write("Hello World!\r");
} catch (Exception ex) {
Log.d(TAG, "Error in Zigbee Service: " + ex.toString());
}
我收到了写着 “Context.ZIGBEE_SERVICE” 错误。它说:“当我把光标放在它上面时,必须是:所有系统服务列表”中的一个:。 使用其他系统服务工作。与其他系统服务一样,Zigbee服务也可以在Context.class文件中使用。
...
public static final String WIFI_SERVICE = "wifi";
public static final String WINDOW_SERVICE = "window";
public static final String ZIGBEE_SERVICE = "zigbee";
现在,当它在设备上运行它。我在logcat上得到这个错误信息。
01-01 12:09:24.126 6874-6874/com.jcxmej.uartcontrol D/UARTControl: Error in Zigbee Service: java.lang.NullPointerException: Attempt to invoke interface method 'int android.os.IZigbeeService.write(java.lang.String)' on a null object reference
该对象为空。它需要被初始化,但是如何?但我认为这是空的,因为上下文没有正确链接。我如何摆脱上下文错误。或者在Context中正确添加Zigbee服务。
我用它作为参考。 https://github.com/nayobix/add-new-hardware-hal-android-5-lollipop
您发布的参考文献的服务调用如下所示:“SensorHubMgmtManager om =(SensorHubMgmtManager)getSystemService(Context.SENSORHUBMGMT_SERVICE);” – Jim
@Jim是的。与我的相似。 ZigbeeManager zm =(ZigbeeManager)getSystemService(Context.ZIGBEE_SERVICE); – jcxmej
@UmarAta那不是。什么是您的服务? – jcxmej