简体   繁体   English

使用openCSV CSVReader读取csv文件时出现Java应用程序错误... java.lang.ArrayIndexOutOfBoundsException

[英]Java application Error while reading a csv file using openCSV CSVReader … java.lang.ArrayIndexOutOfBoundsException

I get an error in my Java application when i try to read a column from each line of my csv file 当我尝试从我的csv文件的每一行读取一列时,我的Java应用程序出错

java.lang.ArrayIndexOutOfBoundsException: 1

My code is like this using OpenCSV 我的代码就像使用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]);                   
             }}....

It's probably an empty line or comment line in the CSV or something like that. 它可能是CSV中的空行或注释行或类似的东西。 The error means that there is no 2nd value on that row (nextLine[1] is the second value). 该错误意味着该行上没有第二个值(nextLine [1]是第二个值)。 Check your file and print nextLine[0] and you will see the mistake. 检查您的文件并打印nextLine [0],您将看到错误。 nextLine[0] will contain the whole row. nextLine [0]将包含整行。 Make sure you tell openCSV to use the poper separator, escape character etc. 确保告诉openCSV使用poper分隔符,转义字符等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM