Report with parameter in Jaspersoft Studio

Asked

Viewed 201 times

0

I have a java class in netbenas that was to generate a report, according to the Service Order (ID) entered by the user. But Netbeans returns an error "File or report not found".

private void imprimir() {
    int confirma = JOptionPane.showConfirmDialog(null, "Deseja realmente viusalizar o relatório?", "Atenção", JOptionPane.YES_NO_OPTION);
    if (confirma == JOptionPane.YES_OPTION) {
        Map map = new HashMap();
        map.put("cod_solicitante", txtCod.getText());
        JasperReport relatorio;
        JasperPrint impressao;
        try {
            if (!txtCod.getText().equals("")) { // verifica se não está vazia
                relatorio = JasperCompileManager.compileReport(new File("").getAbsolutePath() + "/home/joao/Documentos/NetBeansProjects/ProjetoTCC/src/MyReports/RelatorioRequerente.jrxml");
                impressao = JasperFillManager.fillReport(relatorio, map, conexao); //cria janela com relatório
                JasperViewer viewer = new JasperViewer(impressao, false);
                viewer.setTitle("Requerente de Alvará");
                viewer.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(null, "Selecione um  para impressão");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "ERRO: " + e.getMessage());
        }

    }
}

I have another class that takes all the records and generates normal report

int confirma = JOptionPane.showConfirmDialog(null, "Deseja viusalizar o relatório?", "Atenção", JOptionPane.YES_NO_OPTION);
    if (confirma == JOptionPane.YES_OPTION) {
        try {
            JasperPrint print = JasperFillManager.fillReport("/home/joao/Documentos/NetBeansProjects/ProjetoTCC/src/MyReports/RelatorioVistoria.jasper", null, conexao); // pega o relatorio
            JasperViewer.viewReport(print, false);//abre em modo de visualização

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "ERRO: " + e.getMessage());
        }

    }

Any tips on how to proceed?

  • Did you see that in JasperCompileManager.compileReport you’re passing a path that makes no sense?

  • Do you have any suggestions to change this path?

  • Have you tried that? new File("/home/joao/Documentos/NetBeansProjects/ProjetoTCC/src/MyReports/RelatorioRequerente.jrxml").getAbsolutePath()?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.