Java Application Error while reading csv file with openCSV CSVReader ... java.lang.ArrayIndexOutOfBoundsException

I am getting an error in my Java application when I try to read a column from each line of my csv file

java.lang.ArrayIndexOutOfBoundsException: 1

      

My code is like OpenCSV

    public void insertOjd(String fichierEntree) throws SQLException {
    try {

        CSVReader reader = new CSVReader(new FileReader(fichierEntree));


        String[] nextLine;

            while ((nextLine = reader.readNext()) != null) {
             if (nextLine != null) {

                 System.out.println(nextLine[1]);                   
             }}....

      

+3


source to share


1 answer


It is probably an empty line or a CSV comment line or something. An error means that there is no second value on this line (nextLine [1] is the second value). Check the file and type nextLine [0] and you will see an error. nextLine [0] will contain the entire line. Make sure you tell openCSV to use poker delimiter, escape character, etc.



0


source







All Articles