3
I’m trying to generate a report with Jasper Reports + JSF
and I’m having the following exception:
net.sf.jasperreports.engine.Jrexception: Invalid page index range : 0 - -1 of 0 at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(Jrprinterawt.java:136) at net.sf.jasperreports.engine.Jasperprintmanager.print(Jasperprintmanager.java:229) at net.sf.jasperreports.engine.Jasperprintmanager.print(Jasperprintmanager.java:116) at net.sf.jasperreports.engine.Jasperprintmanager.printReport(Jasperprintmanager.java:313) at bean.InsumesBean.print(Insumosbean.java:95)
That’s my report code:
public void imprimir(){
try{
System.out.println("Imprimir chamado");
String caminho = Faces.getRealPath("/reports/Insumos.jasper");
Map<String, Object> parametros = new HashMap<>();
Connection conexao = HibernateUtil.getConexao();
JasperPrint relatorio = JasperFillManager.fillReport(caminho, parametros, conexao);
System.out.println(relatorio);
JasperPrintManager.printReport(relatorio, true); //Linha do erro
}catch(JRException erro){
Messages.addGlobalError("Ocorreu um erro ao tentar gerar o relatório");
erro.printStackTrace();
}
}//Fim do metodo imprimir
How can I solve this problem?
Whoa, Crislayne, did you check the data source that feeds your report? Do you feed it via Query or would it be by Collection? If it is the case of Collection you are not passing in the code snippet above. Check these details for us!
– Julio Cesar da Silva Barros
Hello, Julio Cesar! So it is by query that I feed with Hibernate connection. When Gero it in Jasper Reports, it generates normal with the database data in preview.
– Crislayne Durante