java.lang.StringIndexOutOfBoundsException:长度=1;索引=1
这是我的密码 打开此活动时应用程序正在崩溃 请帮忙 下面是错误 这不是完整的代码java.lang.StringIndexOutOfBoundsException:长度=1;索引=1,java,android,Java,Android,这是我的密码 打开此活动时应用程序正在崩溃 请帮忙 下面是错误 这不是完整的代码 public void onBindViewHolder(final MyViewHolder holder, final int position) { final ModelTimeSlot modelTimeSlot = arrayList.get(position); holder.checkBox.setText(modelTimeSlot.name); holder.chec
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)
打印
modelTimeSlot.endTime的值并检查其长度。跟踪非常清楚地表明长度小于您要传递的索引,即0
或2
或3
您在arrayList.get(position),arrayList.size()中遇到的问题这会导致异常,请查看您在getCount()中编写的内容方法modelTimeSlot.endTime中有多少个字符
?你试图进入不存在的位置。如果长度为1,那么唯一存在的位置是0。仍然没有得到它printmodelTimeSlot.endTime
man,您将看到modelTimeSlot.endTime
的长度小于3在执行charAt
之前检查长度,例如If(modelTimeSlot.endTime.length()>3){modelTimeSlot.endTime.charAt(3)}