第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我有這個(gè)錯(cuò)誤 java.lang.IndexOutOfBoundsException:

我有這個(gè)錯(cuò)誤 java.lang.IndexOutOfBoundsException:

米脂 2022-12-07 15:09:11
我收到一個(gè)錯(cuò)誤:java.lang.IndexOutOfBoundsException:索引:0,大?。?我遇到錯(cuò)誤的部分在我的 if 語句中onBindViewHolder,下面是我的適配器:public class UserProgramWeekAdapter extends RecyclerView.Adapter<UserProgramWeekAdapter.ViewHolder>{    private Context context;    private ArrayList<ProgramTrackerWrapper> programTrackers;    public UserProgramWeekAdapter(Context context, ArrayList<ProgramTrackerWrapper> programTrackers) {        this.context = context;        this.programTrackers = programTrackers;    }    @Override    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_user_program_week_adapter, parent, false);        ViewHolder viewHolder = new ViewHolder(view);        return viewHolder;    }    @Override    public void onBindViewHolder(UserProgramWeekAdapter.ViewHolder holder, int position) {        holder.dayTxt.setText(programTrackers.get(position).getDay());        holder.numberofExercises.setText(programTrackers.get(position).getProgramTrackers().size()+ " exercises");        boolean isFinished = false;        for (int i = 0; i < programTrackers.size(); i++){        if ( programTrackers.get(position).getProgramTrackers().get(i).isProgramExerciseFinished()){                isFinished = true;            }        }        String statusTxt = isFinished || programTrackers.size() == 0 ? "Completed" : "Not Completed";        holder.exerciseCompleted.setText(statusTxt);    }    @Override    public int getItemCount() {        return programTrackers.size();    }    public class ViewHolder extends RecyclerView.ViewHolder {        TextView dayTxt, exerciseCompleted, numberofExercises;        public ViewHolder(View itemView) {            super(itemView);            dayTxt = itemView.findViewById(R.id.dayTxt);            exerciseCompleted = itemView.findViewById(R.id.exerciseCompleted);            numberofExercises = itemView.findViewById(R.id.numberofExercises);        }    }}
查看完整描述

1 回答

?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

這看起來很可疑:


for (int i = 0; i < programTrackers.size(); i++){

  if ( programTrackers.get(position).getProgramTrackers().get(i).isProgramExerciseFinished()){

        isFinished = true;

    }

}

您檢查programTrackers列表的大小,但不檢查其子列表,因此i很容易指向不正確的索引:


final int sublistSize =  programTrackers.get(position).getProgramTrackers().size();

for (int i = 0; i < sublistSize; i++){

  if (programTrackers.get(position).getProgramTrackers().get(i).isProgramExerciseFinished()){

        isFinished = true;

    }

}


查看完整回答
反對 回復(fù) 2022-12-07
  • 1 回答
  • 0 關(guān)注
  • 127 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號