Java. util. ConcurrentModificationException in android details

Source: Internet
Author: User
Tags concurrentmodificationexception

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.