Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
NoSuchElementException usando la clase Iterator con HashSet

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(); } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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(); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!