
java.lang.arrayindexoutofboundsexception 12
Publicado por Cesar (5 intervenciones) el 08/08/2014 19:33:07
Hola que tal buen dia, me podrian ayudar con un problema que me surgio, lo que sucede es que tengo un jTable y quiero exportar su contenido a un .csv, ya hice mi boton y los metodos de obtener y exportar datos, pero cuando intento exportar mi tabla completa me manda una excepcion (java.lang.arrayindexoutofboundsexception 12), pero esto solo sucede cuando son mas de 12 lineas, siendo menos me hace la exportacion sin ningun problema, parece problema de mi bucle for en el metodo de exportacion pero segun veo esta correcto, me podrian apoyar.
-Estos son los metodos;
OBTENER DATOS DEL JTABLE
public String [][] obtenerdatos(){
int numFilas=tbcrew.getRowCount();
int numColumnas=tbcrew.getColumnCount();
String matrix [][] = new String [numFilas+1][numColumnas];
for (int rowIndex=0;rowIndex<numFilas;rowIndex++){
for (int colIndex=0;colIndex<numColumnas;colIndex++){
matrix[rowIndex][colIndex]=(String)tbcrew.getValueAt(rowIndex, colIndex);
}
}
return matrix;
}
EXPORTAR A ARCHIVO
private void exportActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int resultado = fileChooser.showSaveDialog(this);
if (resultado == JFileChooser.CANCEL_OPTION){
return;
}
File archivo = fileChooser.getSelectedFile();
try{
PrintWriter salida = new PrintWriter(new FileWriter(archivo+".csv"));
String data[][]=obtenerdatos();
for (int i = 0; i<data.length; 0++) {
salida.print(data[i][0]);
for (int j = 1; j<data.length; j++) {
String word = data[i][j];
if(word != null){
salida.print(","+word);
}else{
salida.print(",");
}
}
salida.println();
}
salida.close();
}catch(IOException io){
}
-Estos son los metodos;
OBTENER DATOS DEL JTABLE
public String [][] obtenerdatos(){
int numFilas=tbcrew.getRowCount();
int numColumnas=tbcrew.getColumnCount();
String matrix [][] = new String [numFilas+1][numColumnas];
for (int rowIndex=0;rowIndex<numFilas;rowIndex++){
for (int colIndex=0;colIndex<numColumnas;colIndex++){
matrix[rowIndex][colIndex]=(String)tbcrew.getValueAt(rowIndex, colIndex);
}
}
return matrix;
}
EXPORTAR A ARCHIVO
private void exportActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int resultado = fileChooser.showSaveDialog(this);
if (resultado == JFileChooser.CANCEL_OPTION){
return;
}
File archivo = fileChooser.getSelectedFile();
try{
PrintWriter salida = new PrintWriter(new FileWriter(archivo+".csv"));
String data[][]=obtenerdatos();
for (int i = 0; i<data.length; 0++) {
salida.print(data[i][0]);
for (int j = 1; j<data.length; j++) {
String word = data[i][j];
if(word != null){
salida.print(","+word);
}else{
salida.print(",");
}
}
salida.println();
}
salida.close();
}catch(IOException io){
}
Valora esta pregunta


0