我有一个问题,当我尝试删除arrayList上的元素。我需要在其他数组上放置一些元素,然后从原始数组中删除这些元素。我把下面的代码:异常滚动arraylist第二次
private void setOrderAnswers(int position) {
for (int i = 0; i < 4; i++) {
listAnswersAux.add(listAnswers.get((position * 4) + i));
}
for (int i = 0; i < 4; i++) {
listAnswers.remove((position * 4) + i);
}
}
我的错误是一个例外IndexOutOfBounds:
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
我不知道为什么我有这样的例外,当我尝试删除该索引,但是当我去索引复制元素,没有问题。我的意思是,索引是确定的,因为在删除它之前我可以看到该元素。
而且我总是有索引值= 10的例外,在索引= 10(位置= 2)之前,我可以完成所有这些操作。
任何人都可以帮助我吗?非常感谢!
06-14 09:58:58.455 31337-31337/com.prodintec.am_motion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.prodintec.am_motion, PID: 31337
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prodintec.am_motion/com.prodintec.am_motion.QuizActivity}: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
at java.util.ArrayList.get(ArrayList.java:411)
at com.prodintec.am_motion.QuizActivity.setOrderAnswers(QuizActivity.java:201)
at com.prodintec.am_motion.QuizActivity.randomQuestions(QuizActivity.java:168)
at com.prodintec.am_motion.QuizActivity.onCreate(QuizActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
也许是因为你已经删除了10元在第一次运行? –
@Imrik你能告诉我你的名单的大小以及你使用的是什么类型的名单? – Jeeva
@imrik IndexOutOfBoundsException - 抛出以指示某种类型的索引(例如数组,索引或向量)超出范围。根据Java文档。 – Jeeva