I have a csv file with only one column of values. I would like to take the values from each row and display them in separate TextViews using OpenCSV. My code goes something like this:
try {
CSVReader reader = new CSVReader(new FileReader(csvInPath));
String [] row;
while ((row = reader.readNext()) != null) {
tvN[1].setText(row[1].toString());
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
It gives me an ArrayIndexOutOfBoundsException error in LogCat and the app force closes. Can someone tell me what I'm doing wrong and how to do this right? Thanks.
As greenapps pointed out, I was referencing to row[1], which does not exist, as I only have 1 column of values. Turns out OpenCSV reads csv files column by column, and since I had only 1 column, I had to either use row[0], or make my csv have multiple columns. ie: My csv file:
What I should use: 1. Name 2. Name2 3. Name3
It would also be better to rename row[] to column[] to avoid any confusion.