ArrayIndexOutOfBoundsException
この関数を呼び出すと取得されますが、常にではありません。10回の試行のうち、3回エラーが発生し、残りの7回は完全に機能しました.
void readTrainingData(Model m) throws FileNotFoundException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("training_data.csv"));
} catch (IOException ex) {
throw new FileNotFoundException();
}
String line = "";
int i = 0;
int j;
try {
while((line = br.readLine()) != null) {
String[] coords = line.split(",");
if (coords[0] != null && coords[1] != null) {
m.x[i] = Float.parseFloat(coords[0]);
m.y[i] = Float.parseFloat(coords[1]);
}
else {
System.out.println("Check training_data.csv");
}
j = 0;
i++;
}
} catch (IOException ex) {
System.out.println("Problem reading file");
throw new RuntimeException(ex);
}
}
エラーは次のとおりです。
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at polygonprobability.Util.readTrainingData(Util.java:215)
デバッグしようとしてもエラーが発生しないため、デバッグできません。
私は完全に混乱しています。助けてください。
編集:条件をに変更しました
if (coords[0] != null && coords[1] != null && coords.length == 2) {
m.x[i] = Float.parseFloat(coords[0]);
m.y[i] = Float.parseFloat(coords[1]);
}
215 行目はたまたま if 条件そのものです。
変更後もエラーが続きます。