问题:
{
"success": false,
"code": "S0000",
"error": "null [java.lang.IndexOutOfBoundsException,Index: 5, Size: 5]",
"serviceName": "cols-service",
"paramErrors": null
}
原因:
HashMap<String, Object> objectHashMap = new HashMap<>();
List<Map<String,String>> mapList= new ArrayList<>();
HashMap<String, String> hashMap = new HashMap<>();
for (int i=0;i<cardParameterInfoList.size();i++){
Long cardParameterId = cardParameterInfoList.get(i).getCardParameterId();
String value = cardParameterInfoList.get(i).getValue();
for (int j=0;j<cardParameterList.size();i++){
String name = cardParameterList.get(j).getName();
Long id = cardParameterList.get(j).getId();
if (name.equals("FITVersion")){
if (id.equals(cardParameterId)){
objectHashMap.put(name,value);
}
}else{
if (id.equals(cardParameterId)){
hashMap.put(name,value);
}
}
mapList.add(hashMap);
}
}
解决:
HashMap<String, Object> objectHashMap = new HashMap<>();
List<Map<String,String>> mapList= new ArrayList<>();
HashMap<String, String> hashMap = new HashMap<>();
for (int i=0;i<cardParameterInfoList.size();i++){
Long cardParameterId = cardParameterInfoList.get(i).getCardParameterId();
String value = cardParameterInfoList.get(i).getValue();
for (int j=0;j<cardParameterList.size();j++){
String name = cardParameterList.get(j).getName();
Long id = cardParameterList.get(j).getId();
if (name.equals("FITVersion")){
if (id.equals(cardParameterId)){
objectHashMap.put(name,value);
}
}else{
if (id.equals(cardParameterId)){
hashMap.put(name,value);
}
}
mapList.add(hashMap);
}
}
报错,null [java.lang.IndexOutOfBoundsException,Index: 5, Size: 5]
最新推荐文章于 2024-09-10 10:17:32 发布
博客内容涉及一个编程问题,其中在遍历两个列表时,由于循环变量使用错误,导致了`IndexOutOfBoundsException`。作者展示了原始代码中存在错误的循环,并给出了修正后的代码。修正点在于将内部循环的迭代变量`j`的递增操作从`i++`更正为`j++`。这个问题涉及到Java集合操作和异常处理,是编程实践中常见的错误类型。
摘要由CSDN通过智能技术生成