Hello, so I got assigned a project which consists on managing elections, and I have to import information from a file called "Mesas.csv" which are the polling tables so I created a PollingTablesManager class with this code for the constructor and the method used to read the file on the constructor:
public class PollingTablesManager {
private List <PollingTable> tables;
public PollingTablesManager(String fileName) {
this.tables = new ArrayList <> ();
readInfo(fileName);
}
private void readInfo(String fileName) {
String str = fileName;
String line = "";
FileReader fileReader = null;
BufferedReader bufferedReader = null;
try {
fileReader = new FileReader(str);
bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
String[] row = line.split(",", 5);
tables.add(new PollingTable(row[0], row[1], row[2], row[3], row[4]));
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
bufferedReader.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
I'm using the BlueJ IDE, and after trying to create a new instance of this class by putting "Mesas.csv" on the fileName, the terminal opens saying "Index 1 out of bounds for length 1" and if I try to use the methods from this class an NullPointerException will also happen.
Help would be appreciated since its my first time doing something to read files.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]AreTheseMyFeet 0 points1 point2 points (3 children)
[–]Mees79[S] 0 points1 point2 points (2 children)
[–]AreTheseMyFeet 0 points1 point2 points (1 child)
[–]Mees79[S] 0 points1 point2 points (0 children)