Jasper compiler error when using SUM method

穿精又带淫゛_ 提交于 2021-02-18 17:14:47

问题


I'm using the Jasper built-in SUM function in a cell of a table. It should sum the content of other cells (in the example I'm using a single cell, but the output is pretty much the same adding multiple cells).

The jrxml is:

<jr:column width="49" uuid="e6595bc8-b46e-4bbe-85a2-7ea9526fce83">
 <property name="local_mesure_unitwidth" value="pixel"/>
  <jr:columnHeader style="Table 2_CH" height="20">
    <staticText>
     <reportElement x="2" y="0" width="47" height="20" uuid="af5e8305-5cdf-41ad-b827-80f0ca14771c"/>
     <textElement textAlignment="Center" verticalAlignment="Middle"/>
     <text><![CDATA[Nr. Prest.]]></text>
    </staticText>
  </jr:columnHeader>
  <jr:detailCell style="Table 2_TD" height="30">
   <textField>
    <reportElement x="0" y="0" width="49" height="30" uuid="8cc69012-6972-470a-92f4-e735f8d006d8"/>
    <textFieldExpression><![CDATA[SUM($F{1})]]></textFieldExpression>
   </textField>
  </jr:detailCell>
</jr:column>

In Jasper Studio is working correctly, but when I try to compile the report using maven plugin or using the JasperCompileManager it returns these errors

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method SUM(Integer) is undefined for the type report1_dataset1_1389172627824_411632
            value = SUM(((java.lang.Integer)field_j49.getValue())); //$JR_EXPR_ID=41$
                    <->
2. The method SUM(Integer) is undefined for the type report1_dataset1_1389172627824_411632
            value = SUM(((java.lang.Integer)field_j49.getOldValue())); //$JR_EXPR_ID=41$
                    <->
3. The method SUM(Integer) is undefined for the type report1_dataset1_1389172627824_411632
            value = SUM(((java.lang.Integer)field_j49.getValue())); //$JR_EXPR_ID=41$
                    <->
3 errors

net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:241)

I upgraded to latest Jasper version (5.5.0) but the result is the same.


回答1:


From [jaspersoft download][1]

[1]: http://jaspersoft.artifactoryonline.com/jaspersoft/jr-ce-releases/net/sf/jasperreports/jasperreports-functions/5.5.0/ download the jasperreports-functions-5.5.0.jar and place it in your class path.




回答2:


change

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

to

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

and assign the expression as

<textFieldExpression><![CDATA[SUM($F{one})]]></textFieldExpression>



回答3:


I solved the compilation problem changing the report language from Java to Javascript:

<jasperReport ... name="report_name" language="javascript" ...>


来源:https://stackoverflow.com/questions/20991641/jasper-compiler-error-when-using-sum-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!