2012-03-29 69 views
0

我有一個類的arraylist,當我執行下面的函數時,我有時會得到一個StackOverflowError,我不是100%確定爲什麼,肯定if語句應該排除?它只包含< 500個元素,沒有其他線程擺弄「toCheck」。StackOverflowError當刪除ArrayList對象

if(toCheck.contains(currentConsideration)){ 
    toCheck.remove(currentConsideration); 
} 

任何幫助將不勝感激!

+3

你可以張貼currentConsideration對象的equals方法? – 2012-03-29 13:18:01

+1

這段代碼看起來不錯。但我懷疑它在循環中使用。你能給我們更多的代碼嗎? – bigGuy 2012-03-29 13:19:26

+3

嘗試刪除'toCheck.contains(currentConsideration)'並僅使用'toCheck.remove(currentConsideration);'。如果存在,它將刪除該元素。 – 2012-03-29 13:20:23

回答

0

這可能是因爲您正在嘗試刪除您嘗試在列表中找到它的對象... ConcurrentModificationException。

如果您嘗試調試。什麼時候你會得到那朵錯誤

發佈的解決方案,如果您發現有任何