net.sf.jasperreports.engine.JRException:页面索引范围无效:0 - -1为0

时间:2015-09-02 17:52:18

标签: java jasper-reports

当我尝试打印Jasper报告时,它会收到消息:“net.sf.jasperreports.engine.JRException:无效的页面索引范围:0 - -1 of 0”。

代码:

    try {
        JasperPrint impressao = JasperFillManager.fillReport(getClass().getClassLoader().getResourceAsStream("example.jasper"), parametros);
        JasperExportManager.exportReportToPdf(impressao);

        JasperPrintManager.printReport(impressao, true);  
    } catch (JRException e) {
        e.printStackTrace();
    }

报告:

<?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>

有人可以帮我弄清楚它为什么会发生吗?

1 个答案:

答案 0 :(得分:5)

JasperFillManager喜欢获取数据源,即使你真的没有。您可以尝试将空数据源作为第三个参数添加到JasperFillManager.fillReport:

JasperPrint impressao = JasperFillManager.fillReport(getClass().getClassLoader().getResourceAsStream("example.jasper"), parametros, new JREmptyDataSource());