I have reviewed all the previous questions with a similar title as this one, however I can't find a solution. All the errors are suggesting that I am not initializing the ArrayList.. Am I not initializing the ArrayList as such with, = new ArrayList<Double> ?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.PrintWriter;
public class main
{
public static void main (String[] args) throws FileNotFoundException
{
ArrayList<Double> RPM, bCoeffs, filteredRPM = new ArrayList<Double>();
Scanner RPMFile = new Scanner(new File("RotationSpeed.txt"));
while(RPMFile.hasNextLine()){
String line = RPMFile.nextLine();
Scanner scanner = new Scanner(line);
scanner.useDelimiter(",");
while(scanner.hasNextDouble()){
RPM.add(scanner.nextDouble());
}
scanner.close();
}
RPMFile.close();
int windowSize = 10;
int filterItterations = 1;
for (int i = 0; i < windowSize; i++){
double temp = 1/windowSize;
bCoeffs.add(temp);
}
for (int k = 1; k <= filterItterations; k++){
if (k == 1){
for (int n = windowSize; n < RPM.size(); n++){
int m = 0;
double tempYSum = 0;
for (int j = 0; j < windowSize; j++){
double tempY = (bCoeffs.get(j))*(RPM.get(n-m));
tempYSum += tempY;
m++;
}
filteredRPM.add(tempYSum);
}
}else{
int i = 1;
for (int n = windowSize; n < filteredRPM.size(); n++){
int m = 0;
double tempYSum = 0;
for (int j = 0; j < windowSize; j++){
double tempY = (bCoeffs.get(j))*(filteredRPM.get(n-m));
tempYSum += tempY;
m++;
}
filteredRPM.set(i, tempYSum);
i++;
}
}
}
}
}
the errors I am receiving are as follows:
main.java:20: error: variable RPM might not have been initialized
RPM.add(scanner.nextDouble());
^
main.java:31: error: variable bCoeffs might not have been initialized
bCoeffs.add(temp);
^
main.java:36: error: variable RPM might not have been initialized
for (int n = windowSize; n < RPM.size(); n++){
^
main.java:40: error: variable bCoeffs might not have been initialized
double tempY = (bCoeffs.get(j))*(RPM.get(n-m));
^
main.java:52: error: variable bCoeffs might not have been initialized
double tempY = (bCoeffs.get(j))*(filteredRPM.get(n-m));
^
5 errors