【问题标题】:JasperReports: error print variable for crosstab in iReportJasperReports:iReport 中交叉表的错误打印变量
【发布时间】:2012-06-18 10:11:08
【问题描述】:

我在使用 crosstab 运行报告时遇到问题。错误是:

错误填充打印...错误评估表达式: 源文本:$V{cat_code} net.sf.jasperreports.engine.fill.JRExpressionEvalException:评估表达式时出错: 源文本:$V{cat_code}

我可以知道我的源代码有什么问题吗?这是我的代码:

<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="Corr_ticket" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="NoDataSection" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<?xml version="1.0" encoding="UTF-8"?>
    <import value="com.google.common.base.*"/>
    <style name="Crosstab Data Text" hAlign="Center"/>
    <parameter name="daterangefrom" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <parameter name="daterangeto" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <parameter name="monthy" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <parameter name="yrs" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <parameter name="quarter" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <parameter name="weeks" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <queryString>

    </queryString>
    <field name="daterange" class="java.lang.String"/>
    <field name="ticketid" class="java.lang.Integer"/>
    <field name="cat_code" class="java.lang.Integer"/>
    <field name="descategory" class="java.lang.String"/>
    <field name="subcat_code1" class="java.lang.Integer"/>
    <field name="dessub1cat" class="java.lang.String"/>
    <field name="subcat_code2" class="java.lang.Integer"/>
    <field name="dessub2cat" class="java.lang.String"/>
    <field name="description_sub" class="java.lang.String"/>
    <field name="description_source" class="java.lang.String"/>
    <pageHeader>
        <band height="141">
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement x="0" y="53" width="802" height="35" isRemoveLineWhenBlank="true"/>
                <textElement>
                    <font size="11" isBold="true"/>
                    <paragraph lineSpacing="1_1_2"/>
                </textElement>
                <textFieldExpression><![CDATA[(!Strings.isNullOrEmpty($P{daterangefrom}) && !Strings.isNullOrEmpty($P{daterangeto}) && Strings.isNullOrEmpty($P{weeks}) && Strings.isNullOrEmpty($P{monthy}) && Strings.isNullOrEmpty($P{quarter}) && Strings.isNullOrEmpty($P{yrs})) ? "Date Ticket Created From : " + $P{daterangefrom} +"\n" + "Date Ticket Created to : " + $P{daterangeto}
 : null]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="119" width="100" height="20"/>
                <textElement>
                    <font size="11" isBold="true"/>
                </textElement>
                <text><![CDATA[State :]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="98" width="90" height="20"/>
                <textElement>
                    <font size="11" isBold="true"/>
                </textElement>
                <text><![CDATA[Industry Group :]]></text>
            </staticText>
        </band>
    </pageHeader>
    <summary>
        <band height="297">
            <crosstab>
                <reportElement x="0" y="0" width="802" height="297"/>
                <rowGroup name="ticketid" width="70" totalPosition="End">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{ticketid}]]></bucketExpression>
                    </bucket>
                    <crosstabRowHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textField>
                                <reportElement style="Crosstab Data Text" x="0" y="0" width="70" height="25"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$V{ticketid}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabRowHeader>
                    <crosstabTotalRowHeader>
                        <cellContents backcolor="#BFE1FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <staticText>
                                <reportElement x="0" y="0" width="70" height="25"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <text><![CDATA[Total ticketid]]></text>
                            </staticText>
                        </cellContents>
                    </crosstabTotalRowHeader>
                </rowGroup>
                <columnGroup name="cat_code" height="30" totalPosition="End">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{cat_code}]]></bucketExpression>
                    </bucket>
                    <crosstabColumnHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textField isBlankWhenNull="true">
                                <reportElement style="Crosstab Data Text" x="0" y="0" width="100" height="30"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$V{cat_code}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabColumnHeader>
                    <crosstabTotalColumnHeader>
                        <cellContents backcolor="#005FB3" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <staticText>
                                <reportElement x="0" y="0" width="50" height="60" forecolor="#FFFFFF"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <text><![CDATA[Total cat_code]]></text>
                            </staticText>
                        </cellContents>
                    </crosstabTotalColumnHeader>
                </columnGroup>
                <columnGroup name="description_source" height="30" totalPosition="End">
                    <bucket class="java.lang.String">
                        <bucketExpression><![CDATA[$F{description_source}]]></bucketExpression>
                    </bucket>
                    <crosstabColumnHeader>
                        <cellContents backcolor="#F0F8FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <textField>
                                <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$V{description_source}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabColumnHeader>
                    <crosstabTotalColumnHeader>
                        <cellContents backcolor="#BFE1FF" mode="Opaque">
                            <box>
                                <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                            </box>
                            <staticText>
                                <reportElement x="0" y="0" width="50" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <text><![CDATA[Total description_source]]></text>
                            </staticText>
                        </cellContents>
                    </crosstabTotalColumnHeader>
                </columnGroup>
                <measure name="description_sourceMeasure" class="java.lang.Integer" calculation="Count">
                    <measureExpression><![CDATA[$F{description_source}]]></measureExpression>
                </measure>
                <crosstabCell width="50" height="25">
                    <cellContents>
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell height="25" rowTotalGroup="ticketid">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell width="50" columnTotalGroup="cat_code">
                    <cellContents backcolor="#005FB3" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell rowTotalGroup="ticketid" columnTotalGroup="cat_code">
                    <cellContents backcolor="#005FB3" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell width="50" columnTotalGroup="description_source">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
                <crosstabCell rowTotalGroup="ticketid" columnTotalGroup="description_source">
                    <cellContents backcolor="#BFE1FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{description_sourceMeasure}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabCell>
            </crosstab>
        </band>
    </summary>
</jasperReport>

其他问题:- 我认为问题是“表达式类”,因为我的字段有字段名称 =“cat_code”class=“java.lang.Integer”,而我在交叉表中的变量有桶 class=“java.lang.String”。如何处理这种情况?

【问题讨论】:

  • 在我看来,您缺少 $V{cat_code} 定义
  • 我认为问题出在“表达式类”,因为我的字段有 并且我在交叉表中的变量有 .这种情况如何处理?
  • 你知道如何解决这个问题吗?.:(

标签: jasper-reports ireport


【解决方案1】:

您没有名为cat_code 的变量,因为错误消息中的$V{cat_code} 表明您有。你确实有一个名为cat_code的字段:

<field name="cat_code" class="java.lang.Integer"/>

我的猜测是你忘记定义一个名为 this 的变量。您可以在 iReport 中通过右键单击变量部分并单击 Add Variable 来执行此操作。然后,您只需将其定义为您想要的。

我从来没有使用过交叉表,所以这可能是完全错误的,但也许你的意思是$F{cat_code}

【讨论】:

  • 问题不是变量而是类。$V{cat_code} 和 $F{cat_code} 之间存在差异,因为它使用不同的类。我不知道如何处理这种情况。
猜你喜欢
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 2021-09-17
  • 2018-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多