Jasperreports, Document Does Not Contain Pages?

Asked

Viewed 1,145 times

-1

Hello, I’m new to Jasperreports and I’m facing a problem to be able to generate my first report (a DANFE), everything I’ve seen about Jasper so far involved database, as my application does not use database ignored this and I’m trying to pass the data via Hashmap, everything seems to be ok, the application works perfectly, but when the report will open I get a message saying that the document has no pages, I tested other JRXML layouts that I found around, no open, follow the code that loads Jasper.

private void loader(){
    try{

        JasperReport jr = JasperCompileManager.compileReport("src/jasper/teste.jrxml");
        Map dados = new HashMap();
        dados.put("Emit_CNPJ", this.nfe.getEmitente().getCnpj());
        JasperPrint jp = JasperFillManager.fillReport(jr, dados);
        JasperViewer jv = new JasperViewer(jp, false);
        jv.setTitle("DANFE");
        jv.setVisible(true);

        debug.log("DANFE carregada com sucesso.");
    }catch(JRException ex){
        debug.log("Falha ao carregar JasperReports.");
        //Logger.getLogger(Visualizer.class.getName()).log(Level.SEVERE, null, ex);
    }
}
  • Your test.jrxml file has all the right parameters?

2 answers

0

The data you want to pass to Jasper, is it in a database? Analyzing your code, I have an example about passing parameters to Jasper, but these data are in a database, check it out:

JasperReport jasperR;
JasperPrint jasperP;
JRResultSetDataSource jrRS;
Map parametros;

rs=stmt.executeQuery("Select * from tabela");
/* implementação da interface JRDataSource para DataSource ResultSet */
jrRS = new JRResultSetDataSource( rs );// no caso, o rs seria o resultado da query.

parametros = new HashMap();
jasperR = JasperCompileManager.compileReport("report1.jrxml");
jasperP = JasperFillManager.fillReport(jasperR, parametros, jrRS);

On the last line, you have 3 parameters, the Jasper report, the hash map as the second, and the result set as the last parameter. I hope I helped you.

  • I did exactly as in the @Thiago example and it didn’t work.. continues to appear document does not contain pages..

0

Hello, I come back here to thank you for the answers, fortunately I already managed to solve the problem, I do not know if it is correct but by now the report is being displayed, as it seems Jasper does not display the report without a "Datasource", so in line:

JasperPrint jp = JasperFillManager.fillReport(jr, dados);

I added a Beancollection by passing an arrayList

... JasperFillManager.fillReport(jr, dados, new JRBeanCollectionDataSource(lista));

that solved the problem.

Browser other questions tagged

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