Jasper报告错误:该报告没有Pages

时间:2017-08-17 11:12:37

标签: java jasper-reports

我确信上述类似的问题已被提出,但所提供的答案似乎并未解决或解决我的问题。我调查了this并关注this tutorial on youtube,但一切似乎都很好,但我的应用程序无效。

我在iReport-5.6.0创建了一个报告,它运行正常,我的意思是它按预期显示报告。现在问题出现了,当我想用​​Java代码打开这个相同的报告时...它说“文档没有页面”。

从我的阅读中我了解到这与我的数据源或与此相关的内容有关,但我无法修复它。

我的Java代码

此代码是我用来运行报告的代码。

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    try {
        conn = con.getConnection();
        JasperReport jasperReport = JasperCompileManager.compileReport(getClass().getResourceAsStream("transrep1.jrxml"));
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
        JasperViewer.viewReport(jasperPrint);
    } catch (JRException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
} 

我的JRXML

     <?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="transrep" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3b8454da-c73e-44b5-8419-6b700bb7a5cb">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString language="SQL">
        <![CDATA[select *
from transactions
Where cashier='jill']]>
    </queryString>
    <field name="id" class="java.lang.Integer">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="inv_number" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="barcode" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="sku" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="description" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="quantity" class="java.lang.Integer">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="discount" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="line_price" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="date" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="cash" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="card" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="cheque" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="other" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="total_amount" class="java.lang.Double">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="cashier" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="60" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="555" height="55" uuid="42374cc0-37f3-45a4-9a48-018a149d5098"/>
                <textElement textAlignment="Center">
                    <font size="16" isBold="true"/>
                </textElement>
                <text><![CDATA[Transactions by Cashier]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="23" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="92" height="20" uuid="012eb72f-85e5-430a-91d9-fc498cff5b66"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[ID]]></text>
            </staticText>
            <staticText>
                <reportElement x="92" y="0" width="92" height="20" uuid="4736ffa3-2266-43e0-a3ad-7d292f049f26"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Invoice #]]></text>
            </staticText>
            <staticText>
                <reportElement x="184" y="0" width="92" height="20" uuid="50dec793-43ff-49ee-91ed-469584c4c5b6"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[SKU]]></text>
            </staticText>
            <staticText>
                <reportElement x="276" y="0" width="92" height="20" uuid="73110a66-5b8a-4cbc-a5f1-a0bced23b51f"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Quantity]]></text>
            </staticText>
            <staticText>
                <reportElement x="368" y="0" width="92" height="20" uuid="35565309-8ede-415c-83d1-e74f6248fdb5"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Total Amount]]></text>
            </staticText>
            <staticText>
                <reportElement x="460" y="0" width="92" height="20" uuid="06e79d8b-1789-4586-b7bd-3cbbb8a325ef"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Cashier]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="21" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="92" height="20" uuid="e2b6453b-900e-4790-8de4-f7145b483b50"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="92" y="0" width="92" height="20" uuid="ad12a306-7ab3-4e38-b339-2c7607093955"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{inv_number}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="184" y="0" width="92" height="20" uuid="fdf9efa8-5849-49d3-b91e-8f822e4675e1"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{sku}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="276" y="0" width="92" height="20" uuid="0843372f-078c-4a93-9bbb-34fb4a1c42ad"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="368" y="0" width="92" height="20" uuid="ddf7abde-9ea0-4c94-8b7e-aba789dec10e"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{total_amount}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="460" y="0" width="92" height="20" uuid="d4aaedef-1880-40cd-b6f1-f4d5eaac587a"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$F{cashier}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="49" splitType="Stretch">
            <textField>
                <reportElement x="210" y="27" width="80" height="20" uuid="7cbceb70-1224-4afc-acfb-4a50a937320b"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="334" y="27" width="40" height="20" uuid="07b25ad8-d771-41f3-81f3-8c57bd529025"/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

那我做错了什么?

0 个答案:

没有答案