私はjava.lang.IndexOutOfBoundsException: Index: 1288, Size: 1287
を取得し続けるこれは最初のforループのArrayList<Formant> stored
を参照しています。私はなぜArrayListの容量が1287に設定されているのか理解していないdp.size
ArrayListが指定した容量に初期化されないのはなぜですか?
誰でも助けてくれますか? 最大ヒープサイズを10Gbに増やしました 私は2048(dpの最大サイズ)に初期容量を設定しようとしました。 関連するコードを以下に示します。
public Formant[] analyzeBuffer(ArrayList<DataPoint> dp) {
//declare variables
int count1 = 0;
int count2 = 0;
ArrayList<DataPoint> stored = new ArrayList<>(dp.size());
Formant[] buffForm = new Formant[12];
//f = new Formant(greatest);
//control for infinit loop
//while loop checks if datapoint is above threshhold, finds the largest number, and removes all datapoints within a given formant
while (!(dp.isEmpty())) {
//checks if data point is above threshold, if yes: stores data point in new arraylist
for (DataPoint td : dp) {
if (td.returnFreq() > threshold) {
stored.add(count1, td);
count1++;
}
//checks if data point is the largest number
if (td.returnFreq() > greatest) {
greatest = td.returnFreq();
f = new Formant(greatest);
}
}
//only removes data points that are formants
//removes all data points within a given formant
if (f.isFormant) {
buffForm[count2] = f;
count2++;
for (int k = 0; k < stored.size(); k++) {
if (stored.get(k).returnFreq() <= (f.determineFormant() + 150) && stored.get(k).returnFreq() >= (f.determineFormant() - 150)) {
stored.remove(k);
}
}
}
//if freqeuncy is not formant remove all instances of that data point
else{
buffForm[count2] = f;
count2++;
for (int k = 0; k < stored.size(); k++) {
if (stored.get(k).returnFreq() == f.freq) {
stored.remove(k);
}
}
}
}
return buffForm;
}