gabrieldrv Posted March 26, 2020 Share Posted March 26, 2020 I am working on a Java / Swing application with a PostgreSQL database. So far everything is going well. I have made several reports without problems.But now I have the following problem. I have a CatalogoProductos.jasper report (See attached file). With the following parameters:CLIENTE_INFORME_FILTRO java.lang.IntegerPRODUCTO_INFORME_FILTRO java.lang.StringCOMPONENTE_INFORME_FILTRO java.lang.Stringwhich is called from the application using the following codeprivate void btnImprimirActionPerformed(ActionEvent evt) { /* Base del informe */ EngineReports informe = new EngineReports("/reports/CatalogoProductos.jasper", "CATALOGO DE PRODUCTOS - FICHA"); /* Parametrización del informe */ String prtComponente = vista.getListaComponenteId().getIdentificadorCadena(vista.getLstComponente().getSelectedValue()); informe.setParametros("COMPONENTE_INFORME_FILTRO", prtComponente); int prtClliente = vista.getListaClienteId().getIdentificadorInt(vista.getLstCliente().getSelectedValue()); informe.setParametros("CLIENTE_INFORME_FILTRO", prtClliente); String prtProducto = vista.getLstProducto().getSelectedValue(); informe.setParametros("PRODUCTO_INFORME_FILTRO", prtProducto); /* Generación del informe */ informe.getInforme();}[/code]The class in charge of the work is as follows:package com.m3dsa.gci.controller;import com.m3dsa.gci.app.Inicio;import com.m3dsa.gci.model.PostgreSQL;import com.m3dsa.gci.view.Application;import java.sql.Connection;import java.sql.SQLException;import java.util.HashMap;import javax.swing.JDialog;import javax.swing.JOptionPane;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.util.JRLoader;import net.sf.jasperreports.view.JasperViewer;/** * * @author Elio Gabriel Drovandini * @version 1.0 */public class EngineReports { /** * Constructor por defecto */ public EngineReports() { datos = PostgreSQL.getInstancia(); conn = datos.getConeccionOn(); parametros = new HashMap<String, Object>(); } /** * Constructor de clase * * @param recursoInforme Ruta relativa de recurso al informe de Jasper */ public EngineReports(String recursoInforme, String titulo) { this(); rutaRelativaRecurso = recursoInforme; this.titulo = titulo; } /** * Fija los parámetros de filtrado del informe * * @param <T> Parámetrización del método * @param nombreParametro Nombre de la variable en el informe Jasper * @param tipoParametro Tipo de datos de la variable de parámetro */ public <T> void setParametros(String nombreParametro, T tipoParametro) { parametros.put(nombreParametro, tipoParametro); } private void setCampos() { rutaInforme = getClass().getResource(rutaRelativaRecurso).getPath().replaceFirst("/", "").replace("%20", " "); String app_denominacion = Inicio.appNombre + " V " + Inicio.versionApp; parametros.put("APP_DENOMINACION", app_denominacion); parametros.put("TITULO_INFORME", titulo); String paramDomicilio = Inicio.comDomicilio + ", " + Inicio.comLocalidad + " - " + Inicio.comProvincia + " (" + Inicio.comPais + ")"; parametros.put("EMPRESA_DOMICILIO", paramDomicilio); parametros.put("CUIT_NUMERO", Inicio.cuit); parametros.put("CORREO_ELECTRONICO", Inicio.correo); String telFax = Inicio.telefono + " / FAX | " + Inicio.fax; parametros.put("TELEFONOS", telFax); parametros.put("LOGO_EMPRESA", getClass().getResourceAsStream("/images/empresa_logo.png")); parametros.put("EMISOR_INFORME", Application.getUsuario()); } /** * Ejecuta el informe del cual se ha pasado su ruta relativa a los recursos */ public void getInforme() { /* Se personaliza el informe con los campos privados de la empresa */ setCampos(); try { informe = (JasperReport) JRLoader.loadObjectFromFile(rutaInforme); JasperPrint impresora = JasperFillManager.fillReport(informe, parametros, conn); JasperViewer visor = new JasperViewer(impresora, false); visor.setDefaultCloseOperation(JasperViewer.DISPOSE_ON_CLOSE); visor.setVisible(true); } catch (JRException ex) { //Logger.getLogger(InformeSinFiltros.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex.getMessage(), Inicio.appNombre, JOptionPane.ERROR_MESSAGE); } finally { datos.setConeccionOff(); } } /** * Ejecuta el informe incrustado en un JDialog para salvar el inconveniente * de la modalidad */ public void getDlgInforme(JDialog base) { /* Se personaliza el informe con los campos privados de la empresa */ setCampos(); /* Se declara el dialogo contenedor del visor de informe */ JDialog contenedor = new JDialog(base); try { informe = (JasperReport) JRLoader.loadObjectFromFile(rutaInforme); JasperPrint impresora = JasperFillManager.fillReport(informe, parametros, conn); JasperViewer visor = new JasperViewer(impresora, false); contenedor.setContentPane(visor.getContentPane()); contenedor.setSize(visor.getSize()); contenedor.setResizable(true); contenedor.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); contenedor.setVisible(true); } catch (JRException ex) { //Logger.getLogger(InformeSinFiltros.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex.getMessage(), Inicio.appNombre, JOptionPane.ERROR_MESSAGE); } finally { datos.setConeccionOff(); } } /** * Gestiona la re-conexión a la BBDD */ private void setReconexion() { try { if (conn.isClosed()) { conn = datos.getConeccionOn(); } } catch (SQLException ex) { //Logger.getLogger(CatalogoDAO.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, ex.getMessage(), Inicio.appNombre, JOptionPane.ERROR_MESSAGE); } } /* Declaración de campos de clase de desarrollador */ private PostgreSQL datos; private Connection conn; private String rutaRelativaRecurso, rutaInforme, titulo; private JasperReport informe; private JasperPrint impresora; private JasperViewer visor; private HashMap<String, Object> parametros; /* Fin de declaración de campos de clase de desarrollador */}[/code]When I run it, I get the following error: The error stems from the code exception for the EngineReports.class class. But I can't find where the error is. Thank you in advance for your help. Best regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now