I had the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
This error is generated when generating a PDF file that is already open, if it is closed it creates it but if it is open it jumps that exception. It should be controlled.
My question is:
Can a try
include two catch
? Can two exceptions be within a catch?
Code :
private void button_listaActionPerformed(java.awt.event.ActionEvent evt) {
try {
ArrayList<Cliente> clientes = Conexiones.listado_clientes();
PDF_Clientes.crearPDF(clientes);
JOptionPane.showMessageDialog(null, "PDF generado correctamente en directorio actual.");
} catch (DocumentException ex) {
Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Error al crear el PDF.");
} catch (NullPointerException npe) {
Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, npe);
JOptionPane.showMessageDialog(null, "El fichero está abierto. Debe cerrarlo.");
}
}
How should it be controlled? Is the solution fine?
The JOptionPane messages work for me but I get the following error in the console / Output:
GRAVE: null
java.lang.NullPointerException