问题描述
我是 BLE android 的新手……我指的是图书馆 SimpleBle。现在的问题是它显示空对象引用。
java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.BluetoothGattCharacteristic android.bluetooth.BluetoothGattService.getCharacteristic(java.util.UUID)' on a null object reference
at com.example.trysimpleagain.utils.BluetoothLEHelper.write(BluetoothLEHelper.java:133)
at com.example.trysimpleagain.MainActivity.lambda$listenerButtons$5$MainActivity(MainActivity.java:192)
at com.example.trysimpleagain.-$$Lambda$MainActivity$lrXzgvPUvAdUlXR4jkWo791A__4.onClick(UnkNown Source:2)
btnWrite.setonClickListener(v -> {
if(ble.isConnected()) {
byte[] aBytes = "Start".getBytes();;
ble.write("40000201-1fb5-459e-8fcc-c5c9c000014b","beb50000-36e1-4688-b7f5-ea07361b0000",aBytes);
}
});
public void write(String service,String characteristic,byte[] aBytes){
BluetoothGattCharacteristic mBluetoothGattCharacteristic;
mBluetoothGattCharacteristic = mBluetoothGatt.getService(UUID.fromString(service)).getCharacteristic(UUID.fromString(characteristic));
mBluetoothGattCharacteristic.setValue(aBytes);
mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic);
}
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)