No entiendo por qué este código me está dando una NoSuchElementException
Esencialmente, lo que estoy haciendo es iterar a través de un HashSet de servidores Gatt y cerrar sus conexiones con un dispositivo si las direcciones de sus dispositivos coinciden.
BluetoothDevice device = mDeselectedDeviceData.device; Iterator<BluetoothGatt> it = BleManager.getInstance().myGattConnections.iterator(); while (it.hasNext()) { if(it.next().getDevice().getAddress() == device.getAddress()){ it.next().close(); } }Esta línea
if(it.next().getDevice().getAddress() == device.getAddress()){esta tirando el error
>NoSuchElementException Sin embargo, it.hasNext() es verdadero si lo registro
while (it.hasNext()) { Log.(TAG,"it.hasNext() is "+String.valueOf(it.hasNext())); // Prints true if(it.next().getDevice().getAddress() == device.getAddress()){ it.next().close(); } }if(it.next().getDevice().getAddress() == device.getAddress()){ it.next().close(); } Lo it.next() dos veces aquí, y avanza el iterador dos posiciones. Estoy bastante seguro de que lo que quieres decir aquí es
BluetoothGatt gatt = it.next(); if(gatt.getDevice().getAddress() == device.getAddress()){ gatt.close(); }