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.