Dr.Android Dr.Android - 1 month ago 30
Android Question

IndexOutOfBoundsException Invalid index 10, size is 10

straightforward indexOutOfBoundsException problem, I'm not seeing my error here. I have an arrayList of 10 objects called "tempbox". And on the line of

tempFolders.get(j).addCardToFolder(tempBox.get(i));
I'm getting the crash... I hope you guys can help point out the problem!

Cheers!

ArrayList<CardModel> toRemove = new ArrayList<>();
for(int i = 0; i < tempBox.size(); i++)
{
if(tempBox.get(i).getCardID() == cardID)
{
for(int j = 0; j < tempFolders.size(); i++)
{
if(tempFolders.get(j).getSelected())
{
Log.d("testing","pass3");
tempFolders.get(j).addCardToFolder(tempBox.get(i));
}
}
}
toRemove.add(tempBox.get(i));
}
Log.d("testing","pass4");
tempBox.removeAll(toRemove);


Here's my stack trace

FATAL EXCEPTION: AsyncTask #6
Process: com.daprlabs.aaron.swipedeck2, PID: 15413
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 10, size is 10
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at com.daprlabs.aaron.swipedeck2.MainActivity$FoldersAsyncTask.putCardIntoSelectedFolders(MainActivity.java:730)
at com.daprlabs.aaron.swipedeck2.MainActivity$FoldersAsyncTask.doInBackground(MainActivity.java:712)
at com.daprlabs.aaron.swipedeck2.MainActivity$FoldersAsyncTask.doInBackground(MainActivity.java:688)
at android.os.AsyncTask$2.call(AsyncTask.java:295)

Answer
for(int j = 0; j < tempFolders.size(); i++) //must be j++