java.lang.StringIndexOutOfBoundsException:length = 1;索引= 1

时间:2016-08-19 17:23:03

标签: java android

这是我的代码 打开此活动时应用程序崩溃 请帮忙 以下是错误 这不是完整的代码

public void onBindViewHolder(final MyViewHolder holder, final int position) {

    final ModelTimeSlot  modelTimeSlot = arrayList.get(position);
    holder.checkBox.setText(modelTimeSlot.name);
    holder.checkBox.setChecked(modelTimeSlot.selected);
    holder.checkBox.setTag(new Integer(position));
    int hr = Integer.parseInt(currentHrs);
    int minutes = Integer.parseInt(currentMin);
    int h = Integer.parseInt(String.valueOf(modelTimeSlot.endTime.charAt(0))
            + String.valueOf(modelTimeSlot.endTime.charAt(1)));

    int m = Integer.parseInt(String.valueOf(modelTimeSlot.endTime.charAt(2))
            + String.valueOf(modelTimeSlot.endTime.charAt(3)));

这是错误

at java.lang.String.indexAndLength(String.java:500)
at java.lang.String.charAt(String.java:494)
at mrhot.com.mrhot.Adapter.AdapterTimeSlot.onBindViewHolder(AdapterTimeSlot.java:91)
at mrhot.com.mrhot.Adapter.AdapterTimeSlot.onBindViewHolder(AdapterTimeSlot.java:28)

2 个答案:

答案 0 :(得分:0)

打印modelTimeSlot.endTime的值并检查其长度。跟踪非常清楚地表明长度小于您传递的索引,即023

答案 1 :(得分:0)

您在arrayList.get(position)中的问题,arrayList.size()<这会导致outOfBound异常,看看你在getCount()方法中写的是什么