Olá, galera…
Eu estou armazenando dados de uma tabela do excel em um vetor, mas esta dando erro.
Alguém sabe o que são esses erros ?
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 3001
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
abaixo esta parte do programa…
[code]
try
{
Workbook workbook = Workbook.getWorkbook(new File(“C:/Documents and Settings/…xls”));
Sheet sheet = workbook.getSheet(0);
File arquivo = new File("C:/Documents and Settings/....xls");
FileReader leitura;
leitura = new FileReader(arquivo);
BufferedReader ler = new BufferedReader(leitura);
int i=1;
while(ler.readLine()!=null)
{
Cell a2 = sheet.getCell(0,i);
String as2 = a2.getContents();
DATA[i]=as2;
System.out.println("Data[" + i + "] : " + DATA[i]);
i++;
}
workbook.close();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (BiffException e)
{
e.printStackTrace();
}[/code]
O programa esta armazenando todos os valores certo, mas devido a esses erros ele é finalizado…
Data[2841] : 8/31/11 11:27
Data[2842] : 8/31/11 11:28
Data[2843] : 8/31/11 11:29
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3001
Data[2844] : 8/31/11 11:30
Data[2845] : 8/31/11 11:31
Data[2846] : 8/31/11 11:32
Data[2847] : 8/31/11 11:33
Data[2848] : 8/31/11 11:34
Data[2849] : 8/31/11 11:35
Data[2850] : 8/31/11 11:36
Data[2851] : 8/31/11 11:37
Data[2852] : 8/31/11 11:38
Data[2853] : 8/31/11 11:39
Data[2854] : 8/31/11 11:40
Data[2855] : 8/31/11 11:41
Data[2856] : 8/31/11 11:42
Data[2857] : 8/31/11 11:43
Data[2858] : 8/31/11 11:44
Data[2859] : 8/31/11 11:45
Data[2860] : 8/31/11 11:46
Data[2861] : 8/31/11 11:47
Data[2862] : 8/31/11 11:48
Data[2863] : 8/31/11 11:49
Data[2864] : 8/31/11 11:50
Data[2865] : 8/31/11 11:51
Data[2866] : 8/31/11 11:52
Data[2867] : 8/31/11 11:53
Data[2868] : 8/31/11 11:54
Data[2869] : 8/31/11 11:55
Data[2870] : 8/31/11 11:56
Data[2871] : 8/31/11 11:57
Data[2872] : 8/31/11 11:58
Data[2873] : 8/31/11 11:59
Data[2874] : 8/31/11 12:00
Data[2875] : 8/31/11 12:01
Data[2876] : 8/31/11 12:02
Data[2877] : 8/31/11 12:03
Data[2878] : 8/31/11 12:04
Data[2879] : 8/31/11 12:05
Data[2880] : 8/31/11 12:06
Data[2881] : 8/31/11 12:07
Data[2882] : 8/31/11 12:08
Data[2883] : 8/31/11 12:09
Data[2884] : 8/31/11 12:10
Data[2885] : 8/31/11 12:11
Data[2886] : 8/31/11 12:12
Data[2887] : 8/31/11 12:13
Data[2888] : 8/31/11 12:14
Data[2889] : 8/31/11 12:15
Data[2890] : 8/31/11 12:16
Data[2891] : 8/31/11 12:17
Data[2892] : 8/31/11 12:18
Data[2893] : 8/31/11 12:20
Data[2894] : 8/31/11 12:21
Data[2895] : 8/31/11 12:22
Data[2896] : 8/31/11 12:23
Data[2897] : 8/31/11 12:24
Data[2898] : 8/31/11 12:25
Data[2899] : 8/31/11 12:26
Data[2900] : 8/31/11 12:27
Data[2901] : 8/31/11 12:28
Data[2902] : 8/31/11 12:29
Data[2903] : 8/31/11 12:30
Data[2904] : 8/31/11 12:31
Data[2905] : 8/31/11 12:32
Data[2906] : 8/31/11 12:33
Data[2907] : 8/31/11 12:34
Data[2908] : 8/31/11 12:35
Data[2909] : 8/31/11 12:36
Data[2910] : 8/31/11 12:37
Data[2911] : 8/31/11 12:38
Data[2912] : 8/31/11 12:39
Data[2913] : 8/31/11 12:40
Data[2914] : 8/31/11 12:41
Data[2915] : 8/31/11 12:42
Data[2916] : 8/31/11 12:43
Data[2917] : 8/31/11 12:44
Data[2918] : 8/31/11 12:46
Data[2919] : 8/31/11 12:47
Data[2920] : 8/31/11 12:48
Data[2921] : 8/31/11 12:49
Data[2922] : 8/31/11 12:50
Data[2923] : 8/31/11 12:51
Data[2924] : 8/31/11 12:52
Data[2925] : 8/31/11 12:53
Data[2926] : 8/31/11 12:54
Data[2927] : 8/31/11 12:55
Data[2928] : 8/31/11 12:56
Data[2929] : 8/31/11 12:57
Data[2930] : 8/31/11 12:58
Data[2931] : 8/31/11 12:59
Data[2932] : 8/31/11 13:00
Data[2933] : 8/31/11 13:01
Data[2934] : 8/31/11 13:02
Data[2935] : 8/31/11 13:03
Data[2936] : 8/31/11 13:04
Data[2937] : 8/31/11 13:05
Data[2938] : 8/31/11 13:06
Data[2939] : 8/31/11 13:07
Data[2940] : 8/31/11 13:08
Data[2941] : 8/31/11 13:09
Data[2942] : 8/31/11 13:10
Data[2943] : 8/31/11 13:11
Data[2944] : 8/31/11 13:12
Data[2945] : 8/31/11 13:13
Data[2946] : 8/31/11 13:14
Data[2947] : 8/31/11 13:15
Data[2948] : 8/31/11 13:16
Data[2949] : 8/31/11 13:17
Data[2950] : 8/31/11 13:18
Data[2951] : 8/31/11 13:19
Data[2952] : 8/31/11 13:20
Data[2953] : 8/31/11 13:21
Data[2954] : 8/31/11 13:22
Data[2955] : 8/31/11 13:23
Data[2956] : 8/31/11 13:24
Data[2957] : 8/31/11 13:25
Data[2958] : 8/31/11 13:26
Data[2959] : 8/31/11 13:27
Data[2960] : 8/31/11 13:28
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
Data[2961] : 8/31/11 13:29
Data[2962] : 8/31/11 13:30
Data[2963] : 8/31/11 13:31
Data[2964] : 8/31/11 13:32
at aaa.main(aaa.java:98)
Data[2965] : 8/31/11 13:33
Data[2966] : 8/31/11 13:34
Data[2967] : 8/31/11 13:35
Data[2968] : 8/31/11 13:36
Data[2969] : 8/31/11 13:37
Data[2970] : 8/31/11 13:38
Data[2971] : 8/31/11 13:39
Data[2972] : 8/31/11 13:40
Data[2973] : 8/31/11 13:41
Data[2974] : 8/31/11 13:42
Data[2975] : 8/31/11 13:43
Data[2976] : 8/31/11 13:44
Data[2977] : 8/31/11 13:45
Data[2978] : 8/31/11 13:46
Data[2979] : 8/31/11 13:47
Data[2980] : 8/31/11 13:48
Data[2981] : 8/31/11 13:49
Data[2982] : 8/31/11 13:50
Data[2983] : 8/31/11 13:51
Data[2984] : 8/31/11 13:52
Data[2985] : 8/31/11 13:53
Data[2986] : 8/31/11 13:54
Data[2987] : 8/31/11 13:55
Data[2988] : 8/31/11 13:56
Data[2989] : 8/31/11 13:57
Data[2990] : 8/31/11 13:58
Data[2991] : 8/31/11 13:59
Data[2992] : 8/31/11 14:00
Data[2993] : 8/31/11 14:01
Data[2994] : 8/31/11 14:02
Data[2995] : 8/31/11 14:03
Data[2996] : 8/31/11 14:04
Data[2997] : 8/31/11 14:05
Data[2998] : 8/31/11 14:06
Data[2999] : 8/31/11 14:07
Data[3000] : 8/31/11 14:08
Java Result: 1
ArrayIndexOutOfBoundsException…
Vamos por partes:
[list]Array = Vetor[/list]
[list]Index = Índice[/list]
[list]Out of Bounds = Fora dos Limites[/list]
[list]Exception = Exceção[/list]
Ou seja, você está tentando acessar um índice que não existe!
Provavelmente é no vetor DATA[] que está dando problema…
fernando, você não leu o
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356) e o at aaa.main(aaa.java:98 )
Destronoyzer, seu código está estranho, você está fazendo um loop baseado na quantidade de linhas que um arquivo excel tem, porém, a não ser que ele seja um csv ele não funciona exatamente assim
Eu acho que o problema está na linha :
while(ler.readLine()!=null)
Você teria que usar alguma funçao da proprio classe Sheet para fazer o loop, no POI da Apache tem a função sheet.getPhysicalNumberOfRows(), que pega a quantidade de colunas do excel e fazer uma iteração com as linhas
Opa… Foi mal.
Falha no engano…
Consegui !!!
Muito obrigado pelo ajuda…
O erro do programa abaixo esta na linha 20, i++.
Mas se eu retirar ele, eu fico com outro problema.
Pesquisei o que vc falou mcarabolante e encontrei uma forma de saber a primeira e a ultima linha do excel. Vou usar isso…
[code] OIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(“C:/Documents and Settings/aaa.xls”));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet5 = wb.getSheetAt(0);
INTERVALO_INICIO = sheet5.getFirstRowNum();
INTERVALO_FIM = sheet5.getLastRowNum();
for(int i=INTERVALO_INICIO;i<=INTERVALO_FIM;i++)
...
[/code]
Valeu pela ajuda e pela atencao…