Im running android studio 4.1.2 im trying to run this transaction:
QuestionDao.kt
@Transaction
suspend fun getRandomRN(num: Int):List<Question>{
val result = getRandomWrongOrNotAnsweredQuestionsByCount(num)
val last = getLastQuizNumber()
val newResult = mutableListOf<Question>()
result?.forEachIndexed{ index,element ->
element.status=0
element.quiz_number = last+1
newResult[index] = element // this is line 91
}
result?.let { updateQuestions(newResult) }
return newResult
}
running app throw error:
com.example.android.myapplication E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-2
Process: com.example.android.myapplication, PID: 25245
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.set(ArrayList.java:453)
at com.example.android.webpooyeshelevatorquize.data.QuestionDao$DefaultImpls.getRandomRN(QuestionDao.kt:91)
QuestionDao.kt:91
is newResult[index] = element
.
BTW the context is Dispachers.IO