Foros del Web » Programación para mayores de 30 ;) » Java »

Error al importar excel

Estas en el tema de Error al importar excel en el foro de Java en Foros del Web. Hola a todos, esto importando unos datos desde un excel a la base de datos, el caso es que los importa bien, pero me salta ...
  #1 (permalink)  
Antiguo 01/02/2016, 15:00
Usuario no validado
 
Fecha de Ingreso: abril-2012
Mensajes: 134
Antigüedad: 12 años, 1 mes
Puntos: 0
Error al importar excel

Hola a todos, esto importando unos datos desde un excel a la base de datos, el caso es que los importa bien, pero me salta una excepción y no doy con la tecla.

Código que lee archivo y vuelca los datos:

Código:
btnImportCustomer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Creamos el file chooser
                JFileChooser fileChooser = new JFileChooser();
                // Indico que solo seleccione archivos
                fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                // Indico los tipos de archivos puede abrir
                FileNameExtensionFilter filter = new FileNameExtensionFilter("XLS files", "xls");
                // Aplico el filtro
                fileChooser.setFileFilter(filter);
                // Muestro el dialog
                int fileSelection = fileChooser.showOpenDialog(jdManageCustomer);
                //Si el usuario, pincha en aceptar
                if (fileSelection == JFileChooser.APPROVE_OPTION) {
                    //Seleccionamos el fichero
                    File file = fileChooser.getSelectedFile();
                    try {
                        // Obtengo la ruta del libro
                        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(file.getAbsolutePath()));
                        //Se obtiene la primera hoja
                        HSSFSheet sheet = workbook.getSheetAt(0);
                        // Contador de celdas
                        int rowCount = sheet.getLastRowNum();
                        // Empiezo en 1 para no leer la cabecera del excel
						for (int i = 1; i < rowCount; i++) {
	                        // Creo el cliente
	                    	Customer customer = new Customer();
				customer.setFirstName(sheet.getRow(i).getCell(0).getStringCellValue());
				customer.setLastName(sheet.getRow(i).getCell(1).getStringCellValue());
				customer.setAddress(sheet.getRow(i).getCell(2).getStringCellValue());
				customer.setPostalCode((int) sheet.getRow(i).getCell(3).getNumericCellValue());
				customer.setPhone((int) sheet.getRow(i).getCell(4).getNumericCellValue());
				customer.setEmail(sheet.getRow(i).getCell(5).getStringCellValue());
				CustomerDAO cust = customerFactory.createCustomerDAO();
                                cust.addCustomer(customer);
                                showCustomerTable();
			}
                        // Cierro el libro
                        workbook.close();
                    } catch (IOException | SQLException ex) {
                        JOptionPane.showMessageDialog(null, "Error de lectura, eliga archivo correcto");
                    }
                }
            }
        });

    }
La excepción:

Código:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at com.maurifuentes.sm.view.ManageCustomerView$10.actionPerformed(ManageCustomerView.java:549)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Exception while removing reference.

Etiquetas: excel, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:48.