我有一个自定义对象的ArrayList,电影将提供有关它们的所有信息。我收到了所有信息,并对其进行了某种排序。然后,它用ReyclerView填充了所有内容。此错误并非始终发生,但有时会出现此错误:
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: took.out.the.package, PID: 10840
java.util.ConcurrentModificationException
at java.util.ArrayList.sort(ArrayList.java:1472)
at java.util.Collections.sort(Collections.java:206)
at took.out.the.package.imdb_activity.sortList(imdb_activity.java:257)
at took.out.the.package.imdb_activity$3.onNetworkResponse(imdb_activity.java:236)
at took.out.the.package.imdb_activity$6.onResponse(imdb_activity.java:412)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
它不会一直发生,我无法弄清楚为什么会发生。这是它调用的方法sortList:
public void sortList()
{
Collections.sort(details, new Comparator<Movie>()
{
@Override
public int compare(Movie left, Movie right)
{
Log.d("compare", "compare: left.getTitle().compareTo(right.getTitle()) = " + left.getTitle().compareTo(right.getTitle()));
return left.getTitle().compareTo(right.getTitle());
}
});
myAdapter.notifyDataSetChanged();
}
任何想法都很棒。我正在用Java执行此操作。