I am writing a file explorer
ArrayList<File> folders = new ArrayList<File>(Arrays.asList(parent
.listFiles(filter)));
ListIterator<File> it = folders.listIterator();
while (it.hasNext()) {
File file = it.next();
if (file.isDirectory())
{
ArrayList<File> subFolders = new ArrayList<File>(
Arrays.asList(file
.listFiles(filter)));
for (File sub : subFolders) {
it.add(sub);
}
}
else
{
mediaFiles.add(file);
}
it.remove();
}
When the code reaches it.remove();, I get the following error:
02-04 23:32:47.670: E/AndroidRuntime(20230): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-04 23:32:47.670: E/AndroidRuntime(20230): at dalvik.system.NativeStart.main(Native Method)
02-04 23:32:47.670: E/AndroidRuntime(20230): Caused by: java.util.ConcurrentModificationException
02-04 23:32:47.670: E/AndroidRuntime(20230): at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:71)
source
share