2015-05-11 41 views
3

我得到了我的Java应用程序中的错误,当我试图从我的CSV文件的每一行读一列的CSV文件Java应用程序错误而阅读使用openCSV CSVReader ... java.lang.ArrayIndexOutOfBoundsException

java.lang.ArrayIndexOutOfBoundsException: 1 

我的代码是这样的使用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

它可能是你在文件中有一大行,没有任何逗号,所以你将只有nextLine [0]创建,当你尝试引用索引1你会得到这个错误 –

回答

0

这可能在CSV空行或注释行或者类似的东西。该错误意味着该行没有第二个值(nextLine [1]是第二个值)。检查你的文件并打印nextLine [0],你会看到错误。 nextLine [0]将包含整行。 请确保你告诉openCSV使用poper分隔符,转义字符等。