Android Details Java.util.ConcurrentModificationException Perverted

Source: Internet
Author: User
Tags concurrentmodificationexception

In today's do Android when the project, I encountered this exception, OK. In fact, the most unusual encounter abnormal illegalstateexception. They are thrown with our hardware connection SDK, and I want to torment students with the Ayu. Pulled away.

Today, I want to go back to this anomaly. Java.util.ConcurrentModificationException abnormal, I froze a bit at the beginning. Seemingly never met this, and then decisive Baidu big God. This only found:

The reason is that when you traverse the collection. caused by the operation of the delete element on the collection. Suppose you have the necessary to delete an element, it is recommended to assign a value to a collection, and then delete the action.

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.


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Android Details Java.util.ConcurrentModificationException Perverted

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.