I am trying to parse a simple csv file in android using the openCSV library. The problem I am runnning into is that it is reading only the first column and nothing else. Can someone look into the code and advice what could be going wrong?
public final List<List<String>> readCsv(Context context) {
List<String> exerciseList = new ArrayList<String>();
List<String> setsList = new ArrayList<String>();
List<String> repsList = new ArrayList<String>();
List<List<String>> combinedList = new ArrayList<List<String>>();
AssetManager assetManager = context.getAssets();
try {
InputStream csvStream = assetManager.open("dummyexerciseplan.csv");
InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
CSVReader csvReader = new CSVReader(new InputStreamReader(getAssets().open("dummyexerciseplan.csv")),',');
String[] line;
// throw away the header
csvReader.readNext();
while ((line = csvReader.readNext()) != null) {
System.out.println(line.toString());
exerciseList.add(line[0]);
setsList.add(line[1]);
repsList.add(line[2]);
}
} catch (IOException e) {
e.printStackTrace();
}
combinedList.add(exerciseList);
combinedList.add(setsList);
combinedList.add(repsList);
return combinedList;
}
This gives an array out of bounds exception since there is the length of the array is only 1 and i am indexing into the second and the third elements as well.
This is what the csv file looks like:
Exercise Name,Sets,Repetitions,Day Of Week
Bent over two-dumbell row,2,12,1
Pull-Ups,2,12,1