Android Details Java.util.ConcurrentModificationException exception

Source: Internet
Author: User

Today in the Android project, encountered this anomaly, well, in fact, usually encountered the most unusual is illegalstateexception, are connected with our hardware SDK thrown out, I tortured the desire to die AH. Pulled away. Say back to today's this anomaly, java.util.ConcurrentModificationException anomaly, at first I froze a bit, seemingly never encountered this, and then decisive Baidu big God, this only found:

The reason is that when you traverse the collection, the delete element is caused by the operation, and if you have to delete the element, it is recommended to assign a value to another collection and then delete it.

Where I have errors:

if (servercards! = null) {for (Paymentcard servercard:servercards) {Mstcard Matchingmstcard = Findmatchingmstcard (server Card,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;
Mstonlycards called in A For loop, the Mstonlycards.remove () method.


Special record, warning.


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.