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.