Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.ConcurrentModificationException

806067Jan 4 2011 — edited Jan 4 2011
Hi All,

I have the following code:
    private static ArrayList<Integer> findCommonMovies(int[] userIDsForReducedIndex) {

        ArrayList<ArrayList> watchedMoviesSet = new ArrayList<ArrayList>();
        for (int i = 0; i < userIDsForReducedIndex.length; i++) {
            ArrayList<Integer> watchedMovies =  findWatchedMovies(userIDsForReducedIndex, trainingMatrix);
watchedMoviesSet.add(watchedMovies);
}

//Initialize the commonMovies with first and second users' common movies
ArrayList<Integer> commonMovies = new ArrayList<Integer>();
ArrayList<Integer> watchedMovies = watchedMoviesSet.get(0);
ArrayList<Integer> watchedMoviesNextUser = watchedMoviesSet.get(1);
for (int movie : watchedMovies) {
for (int movieNextUser : watchedMoviesNextUser) {
if (movie == movieNextUser) {
commonMovies.add(movie);
}
}
}

ArrayList<Integer> tempCommonWatchedMovies = new ArrayList<Integer>();
for (int i = 2; i < watchedMoviesSet.size(); i++) {
ArrayList<Integer> tempWatchedMovies = watchedMoviesSet.get(i);
for (int movie : tempWatchedMovies) {
*** for (int commonMovie : commonMovies) {
if (movie == commonMovie) {
tempCommonWatchedMovies.add(movie);
}
}
}
commonMovies = tempCommonWatchedMovies;
}

return commonMovies;
}
and getting following error related with the line that I put "***":
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at webmining.Main.findCommonMovies(Main.java:273)
at webmining.Main.findSuggestedCommonMovies(Main.java:240)
at webmining.Main.main(Main.java:73)
What's wrong with it? I thought that I can iterate through two ArrayList in a way that I do for arrays.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
This post has been answered by doremifasollatido on Jan 4 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2011
Added on Jan 4 2011
13 comments
163 views