Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
NoSuchElementException using Iterator class with HashSet

I don't udnerstand why this code is giving me a NoSuchElementException

Essentially what I'm doing is iterating across a HashSet of Gatt servers and closing their connections with a device if their device addresses match.

BluetoothDevice device = mDeselectedDeviceData.device;
Iterator<BluetoothGatt> it = BleManager.getInstance().myGattConnections.iterator();
while (it.hasNext()) {
    if(it.next().getDevice().getAddress() == device.getAddress()){ 
        it.next().close();
    }
}

This line

if(it.next().getDevice().getAddress() == device.getAddress()){ 

is throwing the error

>NoSuchElementException

However, it.hasNext() has is true if I log it

while (it.hasNext()) {
    Log.(TAG,"it.hasNext() is "+String.valueOf(it.hasNext())); // Prints true
    if(it.next().getDevice().getAddress() == device.getAddress()){ 
        it.next().close();
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

if(it.next().getDevice().getAddress() == device.getAddress()){ 
    it.next().close();
}

You call it.next() twice here, and it advances the iterator two positions. I'm pretty sure what you mean here is

BluetoothGatt gatt = it.next();
if(gatt.getDevice().getAddress() == device.getAddress()){ 
    gatt.close();
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda