Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda