I need to read from a CSV file in Java, and add the information to a list of string arrays. The problem is the code gives an error while reading the CSV file, but if I take out the CSV column named "Synopsis", the code runs perfectly. It's clear the column has something to do with the codes failure, but I can't figure out what. Anyone have any ideas?
Link to google sheets version of the CSV https://docs.google.com/spreadsheets/d/1EO243KiaZ_uxEKF1mvozONHvTBm5HfFsUvrR5SSB238/edit?usp=sharing
Code here -->
package testerproject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class testerpage {
private List<String[]> list = new ArrayList();
testerpage(){
try {
animeList();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void animeList() throws IOException {
File file = new File("resources/CSVFiles/animeProjectData.csv");
int count = 0; //keep track of where in the list new line is added
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String line = "";
//add line from CSV file to specified list index
while ((line = br.readLine()) != null) {
list.add(count,line.split(","));
count++;
}
} catch (FileNotFoundException e) {
}
System.out.println(list.get(2)[3]);
}
}
Errors given ->
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 1
at testerproject.testerpage.animeList(testerpage.java:37)
at testerproject.testerpage.<init>(testerpage.java:17)
at testerproject.tester.main(tester.java:6)