以下代码导致
java.util.ConcurrentModificationException
我不确定如何解决错误请帮忙!
ArrayList strList = new ArrayList<String>(Arrays.asList(cmd.split(" ")));
if (strList.get(0).equals("LIST")) {
}
if (strList.get(0).equals("DEPEND")) {
strList.remove(0); // getting error at this point
cm.createComponent(strList);
}
完整方法外部循环与列表
无关public static void main(String[] args) throws IOException {
ComponentManager cm = new ComponentManager();
List<String> lines = Files.readAllLines(Paths.get("cmdList.txt"));
for (String cmd : lines) {
ArrayList strList = new ArrayList<String>(Arrays.asList(cmd.split(" ")));
if (strList.get(0).equals("LIST")) {
}
if (strList.get(0).equals("DEPEND")) {
strList.remove(0);
cm.createComponent(strList);
}
if (strList.get(0).equals("INSTALL")) {
}
if (strList.get(0).equals("REMOVE")) {
}
}
}