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