title: Android iBeacon Library ranging api
body: <p>I'm using <a href="https://github.com/RadiusNetworks/android-ibeacon-service" rel="nofollow">Android IBeacon Library</a> and trying to get the number of iBeacons in the region.
  Using the ranging api I get the devices count. This count keeps on changing from 0 to n even when all iBeacons and my phone is still. Also when I try to get the details of the devices I get the following exception. What's causing the exception. When I tried debugging I see the datas are not null.</p>
  
  <pre><code>04-14 11:26:37.203  11754-11883/com.test.ibeacon E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[IBeaconIntentProcessor]
  Process: com.test.ibeacon, PID: 11754
  java.util.NoSuchElementException
          at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
          at com.test.ibeacon.MainActivity$1.didRangeBeaconsInRegion(MainActivity.java:115)
          at com.radiusnetworks.ibeacon.IBeaconIntentProcessor.onHandleIntent(IBeaconIntentProcessor.java:73)
          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:136)
          at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>iBeaconManager.setRangeNotifier(new RangeNotifier() {
          @Override
          public void didRangeBeaconsInRegion(Collection&lt;IBeacon&gt; iBeacons, Region region) {
              Log.d(LOG_TAG,"No of devices == "+iBeacons.size());
              if (iBeacons.size() &gt; 0) {
                  Log.i(LOG_TAG, "The first iBeacon I see is about "+iBeacons.iterator().next().getAccuracy()+" meters away.");
              }
              Iterator&lt;IBeacon&gt; iterator = iBeacons.iterator();
              while (iterator.hasNext()) {
                  Log.d(LOG_TAG,"Major = "+(iterator.next()).getMajor()+" Minor = "+(iterator.next()).getMinor());
              }
          }
      });
  
      try {
          iBeaconManager.startRangingBeaconsInRegion(new Region("myUniqueId", null, null, null)); //I'm specifying the UniqueId.
      } catch (RemoteException e) {   }
  </code></pre>