[英]BLE device services showing null in uiAvailableServices
我已成功連接到BLE設備。 我正在嘗試獲取所有服務並將它們添加到數組中。 但是,當我在uiAvailableServices中循環瀏覽它們時,它顯示為null。
調用可用服務的代碼
@Override
protected void onResume() {
super.onResume();
if(mBleWrapper == null) mBleWrapper = new BleWrapper(this, this);
if(!mBleWrapper.initialize()) {
finish();
}
// start automatically connecting to the device
mBleWrapper.connect(mDeviceAddress);
uiAvailableServices(mBleWrapper.getGatt(), mBleWrapper.getDevice(), mBleWrapper.getCachedServices());
}
availableservices功能:
//add each service to the services array
public void uiAvailableServices(final BluetoothGatt gatt,
final BluetoothDevice device,
final List<BluetoothGattService> services)
{
//services aren't showing up here
for (BluetoothGattService service : services)
{
String uuid = service.getUuid().toString().toLowerCase(Locale.getDefault());
Log.d(TAG, uuid);
}
}
錯誤:
java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
原來我不需要線
uiAvailableServices(mBleWrapper.getGatt(), mBleWrapper.getDevice(), mBleWrapper.getCachedServices());
該行部分用於從服務中檢索特征。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.