Java. util. ConcurrentModificationException in android details
This exception was encountered during the android project today. Well, the most common exception is IllegalstateException, Which is thrown by sdks connected to our hardware, I want to die. Far away. Back to today's exception, java. util. ConcurrentModificationException. At first I paused, and it seems that I have never encountered this before, and then I decided to find out:
The reason is that you deleted the elements of the set when traversing the set. If you need to delete the elements, we recommend that you assign values to another set, then, delete the user.
Where an error occurs:
if (serverCards != null) {for (PaymentCard serverCard : serverCards) {MstCard matchingMstCard = findMatchingMstCard(serverCard,mstCards);ChargecaseCard matchingChargecaseCard = findMatchingChargecaseCard(serverCard, chargecaseCards);if (matchingMstCard != null && matchingChargecaseCard != null) {matchingMstCard.setDominantColor(serverCard.getDominantColor());matchingChargecaseCard.setDominantColor(serverCard.getDominantColor());unifiedCards.add(new UnifiedCard(matchingMstCard,serverCard, matchingChargecaseCard));mstOnlyCards.remove(matchingMstCard);chargecaseOnlyCards.remove(matchingChargecaseCard);} else if (matchingMstCard != null&& matchingChargecaseCard == null) {matchingMstCard.setDominantColor(serverCard.getDominantColor());unifiedCards.add(new UnifiedCard(matchingMstCard,serverCard));mstOnlyCards.remove(matchingMstCard);} else if (matchingMstCard == null&& matchingChargecaseCard != null) {matchingChargecaseCard.setDominantColor(serverCard.getDominantColor());unifiedCards.add(new UnifiedCard(serverCard,matchingChargecaseCard));chargecaseOnlyCards.remove(matchingChargecaseCard);} else {serverOnlyCards.add(serverCard);}}}for (MstCard card : mstOnlyCards) {ChargecaseCard matchingChargecaseCard = findMatchingChargecaseCard(card, chargecaseCards);if (matchingChargecaseCard != null) {matchingChargecaseCard.setDominantColor(card.getDominantColor());unifiedCards.add(new UnifiedCard(card, null,matchingChargecaseCard));chargecaseOnlyCards.remove(matchingChargecaseCard);} else {unifiedCards.add(new UnifiedCard(card));}}for (ChargecaseCard card : chargecaseOnlyCards) {unifiedCards.add(new UnifiedCard(card));}for (PaymentCard card : serverOnlyCards) {unifiedCards.add(new UnifiedCard(card));}return unifiedCards;
In a for loop, mstOnlyCards calls the mstOnlyCards. remove () method.
Special record.