When I try printing the Jasper report it gets me the message: "net.sf.jasperreports.engine.JRException: Invalid page index range : 0 - -1 of 0".
Code:
try {
JasperPrint impressao = JasperFillManager.fillReport(getClass().getClassLoader().getResourceAsStream("example.jasper"), parametros);
JasperExportManager.exportReportToPdf(impressao);
JasperPrintManager.printReport(impressao, true);
} catch (JRException e) {
e.printStackTrace();
}
Report:
<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="base-estadual" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9cbb7afc-abb5-4207-a29b-a0c7adde7df6">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="250"/>
<import value="com.myproject.ed.*"/>
<parameter name="PATH_IMAGENS" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<pageHeader>
<band height="63">
<textField evaluationTime="Report">
<reportElement x="515" y="16" width="40" height="20" uuid="3892152b-6880-41da-bbc7-7bf79588061d"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]>/textFieldExpression>
</textField>
</band>
</pageHeader>
Could someone help me to figure out why is it happening?
JasperFillManager likes to get a data source, even when you don't really have any. You could try adding an empty data source as a third parameter to JasperFillManager.fillReport:
JasperPrint impressao = JasperFillManager.fillReport(getClass().getClassLoader().getResourceAsStream("example.jasper"), parametros, new JREmptyDataSource());