Caute, neviete mi povedat preco mi pise tuto chybu ?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
at triedy.IS.XLS.read(XLS.java:38)
at triedy.IS.XLS.main(XLS.java:67)
Viem ze to znamena ze vychadzam z pola ale nechapem ako....mozte mi niekto pomoct? Dakujem.
package triedy.IS;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class XLS {
private String inputFile;
int[][] pole = new int[50][50];
// Funkcia pre nacitanie buniek
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
int[] hodnota = new int[100];
try {
w = Workbook.getWorkbook(inputWorkbook);
// Nacitavanie prveho harku
Sheet sheet = w.getSheet(0);
// Cyklus pre nacitanie buniek 2 stlpcov a 5 riadkov
Cell[][] cell = new Cell[50][50];
CellType[][] type = new CellType[50][50];
for (int i=4; i<5; i++){
for(int j=19; j<20; j++){
cell[i][j] = sheet.getCell(i,j);
type[i][j] = cell[i][j].getType();
if (cell[i][j].getType() == CellType.LABEL) {
System.out.println("pole "+i+j+" "
+ cell[i][j].getContents());
}
if (cell[i][j].getType() == CellType.NUMBER) {
hodnota[j] = Integer.parseInt(cell[i][j].getContents());
pole[i][j] = hodnota[j];
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
// Funkcia pre vratenie nacitanych hodnot
public int[][] getRead(){
return pole;
}
public static void main(String[] args) throws IOException {
XLS test = new XLS();
test.setInputFile("c:/temp/lars.xls");
test.read();
for (int i=4; i<5; i++){
for(int j=19; j<20; j++){
System.out.println("toto je koncova hodnota navratova " + test.getRead()[i][j]);
}
}
}
}