标签:
今天,我想回到这个异常。java.util.ConcurrentModificationException异常,一開始我愣了一下。貌似从来没遇到过这个,然后果断百度大神。这才发现:
原因是你遍历该集合时。对该集合进行了删除元素的操作导致的。假设你有删除元素的必要,建议赋值到还有一个集合,然后对他进行删除操作.
偶出现错误的地方:
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;在一个for循环中mstOnlyCards调用了,mstOnlyCards.remove()方法。
特记录之,引以为戒。
版权声明:本文博主原创文章。博客,未经同意不得转载。
android详细信息java.util.ConcurrentModificationException变态
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/4806166.html