Database can't retrieve image or empty, cause Array error . how to fix it?

后端 未结 1 528
慢半拍i
慢半拍i 2021-01-26 10:51

My problem is java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0. I don\'t know to fix this error and i not found any problem on my array. I\'m new

相关标签:
1条回答
  • 2021-01-26 11:17

    The problem is this two lines of code:

            quesList=db.getAllQuestions();
            currentQ=quesList.get(qid);
    

    The first line actually just returns an empty array, and hence the second line throws unable to get item at position 0.

    I think it is better to check the length of quesList before accessing it in this case:

    if(quesList.size()>0){
      currentQ=quesList.get(qid);
    }else{
      //maybe put some default question or show no question found message
    }
    
    0 讨论(0)
提交回复
热议问题