title: how to resolve java.util.NoSuchElementException
body: <p>I first had the following code </p>
  
  <p>with the following error message </p>
  
  <pre><code>java.util.ConcurrentModificationException
  java.util.ConcurrentModificationException
          at java.util.HashMap$HashIterator.nextEntry(HashMap.java:894)
          at java.util.HashMap$KeyIterator.next(HashMap.java:928)
          at ca.on.oicr.pinery.lims.gsle.GsleClient.getOrders(GsleClient.java:720)
  </code></pre>
  
  <p>Where line 720 is the second for loop.</p>
  
  <p>I got the answer that I am adding to orders inside a loop that's looping over the elements of orders, that's what causes the exception. Don't modify a collection you're looping over inside the loop. Likewise with samples.</p>
  
  <p>So I re-did this method but I get the following error message:</p>
  
  <pre><code>java.util.NoSuchElementException
  java.util.NoSuchElementException
      at java.util.ArrayList$Itr.next(ArrayList.java:794)
      at ca.on.oicr.pinery.lims.gsle.GsleClient.getOrders(GsleClient.java:730)
  </code></pre>
  
  <p>Where line 730 is Set samples = sampleOrderMap.get(it.next().getId()) in my following code </p>
  
  <p>How would I fix this error message, and will this new method have the same functionality of my original method that did not work, I feel that having all these loops and conditional statements will cause it to not work.</p>