My code goes like this:
HashMap<Integer, ArrayList<DebtCollectionReport>> mapOfAccounts = new HashMap<Integer, ArrayList<DebtCollectionReport>>();
Set<String> agencyNames = agencyWiseAccountMap.keySet();
Iterator iter = agencyNames.iterator();
while (iter.hasNext()) {
String agency = (String) iter.next();
HashMap<Integer, ArrayList<DebtCollectionReport>> tempAccountsMap = agencyWiseAccountMap.get(agency);
Set<Integer> accountSet = tempAccountsMap.keySet();
Iterator itr = accountSet.iterator();
while (itr.hasNext()) {
mapOfAccounts.put((Integer) itr.next(), tempAccountsMap.get((Integer) itr.next()));
}
}
I am getting exception trace:
>
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at com.cerillion.debtcollection.collector.CollectionExecutor.execute(CollectionExecutor.java:56)
at com.cerillion.debtcollection.collector.CollectionExecutor.main(CollectionExecutor.java:24)
2017-11-14 05:00:43,733 ERROR CollectionExecutor [main ] Exception occurred while executing Debt Collection java.util.NoSuchElementException
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at com.cerillion.debtcollection.collector.CollectionExecutor.execute(CollectionExecutor.java:56)
at com.cerillion.debtcollection.collector.CollectionExecutor.main(CollectionExecutor.java:24)
This is occuring for line:
mapOfAccounts.put((Integer) itr.next(), tempAccountsMap.get((Integer) itr.next()));
What can be the possible reason and how can i resolve it ?