我有以下代码,但有时我会java.lang.ArrayIndexOutOfBoundsException
使用subject.gets
. 我不知道这怎么可能发生,但它确实发生了。我有一些多线程正在进行,但这个数组是函数本地的,不能从其他任何地方访问。
// Within onCreate
Random random = new Random();
// some where else
List<Subject> subjects = new ArrayList<Subject>();
// There is SOME CODE HERE TO ADD ELEMENTS.
// There is SOME CODE HERE TO ADD ELEMENTS.
// There is SOME CODE HERE TO ADD ELEMENTS.
// There is SOME CODE HERE TO ADD ELEMENTS.
// There is SOME CODE HERE TO ADD ELEMENTS.
subjects.get(random.nextInt() % subjects.size())