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