java.lang.IndexOutOfBoundsException:索引8无效,大小为8

Goo*_*gle -3 android

for(int j=0; j<ServiceProviderCal.ap_title_arr.size();j++)
{           
    if(ServiceProviderCal.ap_title_arr.get(position).isEmpty())
    {
         Holder.relative.setBackgroundColor(android.graphics.Color.rgb(255, 255,255));
    }
    else
    {
        Holder.txtNote1.setText(notes.get(position)+"  For:");
        Holder.txtNote2.setText(des.get(position));
        Holder.relative.setBackgroundColor(android.graphics.Color.rgb(255, 255,0));                 
        //Log.e("Notes...", ""+notes);  
    }
}
Run Code Online (Sandbox Code Playgroud)

MBy*_*ByD 5

这个:

for(int j=0; j<=ServiceProviderCal.ap_title_arr.size();j++) {
Run Code Online (Sandbox Code Playgroud)

应该:

for(int j=0; j<ServiceProviderCal.ap_title_arr.size();j++) {
Run Code Online (Sandbox Code Playgroud)

数组索引从0开始,因此当您有一个大小为8的数组时,其中的最大索引为7.