JasperStudio交叉表nullpointerexception

时间:2016-04-14 16:33:03

标签: postgresql jasper-reports

我使用Jaspersoft studio 6.2创建报告。我是新手,只是试验交叉表。我在汇总带上放了一个交叉表。数据源是postgresql,查询在postgresql和Dataset和Query Dialog(检测到的字段)中运行正常。交叉表有一个行组和一个列组。

编辑:我更改了查询,因此不需要数据源,但仍然是postgresql查询,因此您可以对其进行验证。我得到了同样的错误。

来源

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
    <!-- 2016-04-15T09:31:15 -->
    <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="test8" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="49d2f486-e168-4ed8-b00a-ba04aabc1354">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
        <style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <queryString>
            <![CDATA[select '2016-04-01'::date as UsageDate, 'a' as ProductName, 1 as CustomerKey
    union all select '2016-04-01'::date as UsageDate, 'b' as ProductName, 2 as CustomerKey
    union all select '2016-05-01'::date as UsageDate, 'a' as ProductName, 2 as CustomerKey
    union all select '2016-05-01'::date as UsageDate, 'b' as ProductName, 3 as CustomerKey]]>
        </queryString>
        <field name="usagedate" class="java.sql.Date"/>
        <field name="productname" class="java.lang.String"/>
        <field name="customerkey" class="java.lang.Integer"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="79" splitType="Stretch"/>
        </title>
        <pageHeader>
            <band height="35" splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band height="61" splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band height="125" splitType="Stretch"/>
        </detail>
        <columnFooter>
            <band height="45" splitType="Stretch"/>
        </columnFooter>
        <pageFooter>
            <band height="54" splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band height="220" splitType="Stretch">
                <crosstab>
                    <reportElement x="272" y="20" width="200" height="200" uuid="27b59abe-7800-4d75-bfde-8ba98dcb63a2">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    </reportElement>
                    <rowGroup name="productname1" width="60" totalPosition="End">
                        <bucket class="java.lang.String">
                            <bucketExpression><![CDATA[$F{productname}]]></bucketExpression>
                        </bucket>
                        <crosstabRowHeader>
                            <cellContents mode="Opaque" style="Crosstab_CH">
                                <textField>
                                    <reportElement x="0" y="0" width="60" height="20" uuid="4d3b9a26-c9ae-4d91-9f9b-046051fe68ef"/>
                                    <textFieldExpression><![CDATA[$V{productname1}]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabRowHeader>
                        <crosstabTotalRowHeader>
                            <cellContents mode="Opaque" style="Crosstab_CT">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="0454ed72-f427-4178-96da-15c3c0120059"/>
                                    <text><![CDATA[Total productname1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalRowHeader>
                    </rowGroup>
                    <columnGroup name="usagedate1" height="20" totalPosition="End">
                        <bucket class="java.sql.Date">
                            <bucketExpression><![CDATA[$F{usagedate}]]></bucketExpression>
                        </bucket>
                        <crosstabColumnHeader>
                            <cellContents mode="Opaque" style="Crosstab_CH">
                                <textField>
                                    <reportElement x="0" y="0" width="60" height="20" uuid="f96354ac-6d2c-4b37-bd70-5f12a1a0d83b"/>
                                    <textFieldExpression><![CDATA[$V{usagedate1}]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabColumnHeader>
                        <crosstabTotalColumnHeader>
                            <cellContents mode="Opaque" style="Crosstab_CT">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="9a5d6927-1279-48b9-85a2-4632d3cf1d73"/>
                                    <text><![CDATA[Total usagedate1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalColumnHeader>
                    </columnGroup>
                    <measure name="customerkey_MEASURE1" class="java.lang.Integer">
                        <measureExpression><![CDATA[$F{customerkey}]]></measureExpression>
                    </measure>
                    <crosstabCell width="60" height="20">
                        <cellContents mode="Opaque" style="Crosstab_CD">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" uuid="5692496d-54c7-473e-b903-56ab136f392e"/>
                                <textFieldExpression><![CDATA[$V{customerkey_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" columnTotalGroup="usagedate1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="ab4186ba-507c-43d1-bd39-36f39ce22e37"/>
                                <textFieldExpression><![CDATA[$V{customerkey_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" rowTotalGroup="productname1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="ecfc705d-bd32-43e2-b1b5-3dec58bdd84e"/>
                                <textFieldExpression><![CDATA[$V{customerkey_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" rowTotalGroup="productname1" columnTotalGroup="usagedate1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="803b9a3e-bb42-4ed4-8d43-ea8451f0f678"/>
                                <textFieldExpression><![CDATA[$V{customerkey_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                </crosstab>
            </band>
        </summary>
    </jasperReport>

数据集查询:

    select '2016-04-01'::date as UsageDate, 'a' as ProductName, 1 as CustomerKey
    union all select '2016-04-01'::date as UsageDate, 'b' as ProductName, 2 as CustomerKey
    union all select '2016-05-01'::date as UsageDate, 'a' as ProductName, 2 as CustomerKey
    union all select '2016-05-01'::date as UsageDate, 'b' as ProductName, 3 as CustomerKey
单击预览时

错误日志

    net.sf.jasperreports.engine.JRException: java.lang.NullPointerException
        at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:524)
        at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$20(ReportControler.java:499)
        at com.jaspersoft.studio.editor.preview.view.control.ReportControler$5.run(ReportControler.java:380)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
    Caused by: java.lang.NullPointerException
        at net.sf.jasperreports.crosstabs.fill.calculation.BucketingService.addMeasure(BucketingService.java:276)
        at net.sf.jasperreports.crosstabs.fill.calculation.BucketingService.<init>(BucketingService.java:135)
        at net.sf.jasperreports.crosstabs.fill.calculation.CrosstabBucketingService.<init>(CrosstabBucketingService.java:59)
        at net.sf.jasperreports.engine.fill.JRFillCrosstab.createService(JRFillCrosstab.java:507)
        at net.sf.jasperreports.engine.fill.JRFillCrosstab.initBucketingService(JRFillCrosstab.java:682)
        at net.sf.jasperreports.engine.fill.JRFillCrosstab$JRFillCrosstabDataset.customInitialize(JRFillCrosstab.java:1191)
        at net.sf.jasperreports.engine.fill.JRFillElementDataset.initialize(JRFillElementDataset.java:148)
        at net.sf.jasperreports.engine.fill.JRCalculator.initializeDataset(JRCalculator.java:556)
        at net.sf.jasperreports.engine.fill.JRCalculator.initializeVariables(JRCalculator.java:322)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:241)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:119)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:558)
        at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:119)
        at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

我终于找到了问题所在。这是因为我将聚合设置为交叉表向导中的不同计数的度量。在我预览报告之前它看起来很好。但是,当双击交叉选项卡时,在“轮廓 - 交叉表 - 测量”中单击度量,在属性中,检查该度量的计算,它是空的!将其更改为Distinct count(或其他),然后运行正常。我认为这可能是一个错误,因为我可以重现它。 BTW度量是java.lang.integer的类型,不确定是否重要。