我试图将循环中生成的数组列表保存到单独的数组列表中。它不允许我这样做;我收到错误:
public static void ranCentroid() {
Random randomPoint = new Random();
Cent = new ArrayList<>();
for (int i = 0; i < numCen; i++) {
int randomP = randomPoint.nextInt(Points.size());
System.out.println(Points.get(randomP));
Cent.get(i).add(randomP);
}
System.out.println(Cent);
}
出现错误
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at phase1.Main.ranCentroid(Main.java:100)
at phase1.Main.main(Main.java:41)
浮云间
www说
相关分类