Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2

Hallo ich bin dabei Daten (zahlen) aus Excel raus zu lesen und wollte sie später in eine neue Einfügen. Nun hab ich folgenen Fehler:
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
    at ExcelAuslesenTest.main(ExcelAuslesenTest.java:21)
C:\Users\User\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Bei folgendem Code:
Java:
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.*;

public class ExcelAuslesenTest{
    public static void main(String[] args) {
        try {
            Workbook wb = Workbook.getWorkbook(new File("C:\\Users\\Timm\\Desktop\\Auslesen.xls"));
            Sheet sheet1 = wb.getSheet(0);
      
      
            Cell colBrow1 = sheet1.getCell(1, 0);
            Cell colBrow2 = sheet1.getCell(1, 1);
            Cell colArow1 = sheet1.getCell(0, 1);
      
            Cell colCrow1 = sheet1.getCell(2, 0);
//            Cell colDrow1 = sheet1.getCell(3, 0);

      
            String str_colBrow1 = colBrow1.getContents();
            String str_colBrow2 = colBrow2.getContents();
            String str_colArow1 = colArow1.getContents();
      
            String str_colCrow1 = colCrow1.getContents();
//            String str_colDrow1 = colDrow1.getContents();

      
            System.out.println("Col B Row 1:  \"" + str_colBrow1 + "\"");
            System.out.println("Col B Row 2:  \"" + str_colBrow2 + "\"");
            System.out.println("Col A Row 1:  \"" + str_colArow1 + "\"");
      
            System.out.println("Col C Row 1:  \"" + str_colCrow1 + "\"");
//            System.out.println("Col D Row 1:  \"" + str_colDrow1 + "\"");

      
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


wenn ich aber colCrow1 rausnehme:
Java:
 Cell colBrow1 = sheet1.getCell(1, 0);
            Cell colBrow2 = sheet1.getCell(1, 1);
            Cell colArow1 = sheet1.getCell(0, 1);
      
//            Cell colCrow1 = sheet1.getCell(2, 0);
//            Cell colDrow1 = sheet1.getCell(3, 0);

      
            String str_colBrow1 = colBrow1.getContents();
            String str_colBrow2 = colBrow2.getContents();
            String str_colArow1 = colArow1.getContents();
      
//            String str_colCrow1 = colCrow1.getContents();
//            String str_colDrow1 = colDrow1.getContents();

      
            System.out.println("Col B Row 1:  \"" + str_colBrow1 + "\"");
            System.out.println("Col B Row 2:  \"" + str_colBrow2 + "\"");
            System.out.println("Col A Row 1:  \"" + str_colArow1 + "\"");
      
//            System.out.println("Col C Row 1:  \"" + str_colCrow1 + "\"");
//            System.out.println("Col D Row 1:  \"" + str_colDrow1 + "\"");

Funktioniert alles einwandfrei, meine Frage weiß jemand wie ich den Fehler beheben kann?
 
Hallo tut mir leid euch gestört zu haben! Bei NetBeans gab es anscheinend das Problem dass es die Main von einer anderen Datei Ausgeführt und dort gab es halt keine Cell mit den Indizes 2,0. Dh. es war ein unbewusster Fehler von NetBeans/Mir.
 
Was soll den Netbeans damit zu tun haben? Egal wie du das ausführst, es wird immer die gleiche Datei geöffnet.
 

Zurück
Oben