Search code examples
jasper-reports

Why do I get error on ABS expression when trying to print band footer?


I am trying to only print a band footer when two number differ from eachother by more than 2. I do not care which one if the larger just that the difference is more than 2. I put into the print when expression a simple formula but I am getting an error.

I have this on my print when expression for a band footer:

ABS($F{rop}-$V{Suggest_ROP}) >= 2.0

but I am getting an error:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The operator >= is undefined for the argument type(s) Number, double
                value = ABS(((java.lang.Double)field_rop.getValue())-((java.lang.Integer)variable_Suggest_ROP.getValue())) >= 2.0; //$JR_EXPR_ID=15$
                        <------------------------------------------------------------------------------------------------------->
2. The operator >= is undefined for the argument type(s) Number, double
                value = ABS(((java.lang.Double)field_rop.getOldValue())-((java.lang.Integer)variable_Suggest_ROP.getOldValue())) >= 2.0; //$JR_EXPR_ID=15$
                        <------------------------------------------------------------------------------------------------------------->
3. The operator >= is undefined for the argument type(s) Number, double
                value = ABS(((java.lang.Double)field_rop.getValue())-((java.lang.Integer)variable_Suggest_ROP.getEstimatedValue())) >= 2.0; //$JR_EXPR_ID=15$
                        <---------------------------------------------------------------------------------------------------------------->
3 errors

at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:215)
at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:195)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.compileJasperDesign(ReportControler.java:439)

Solution

  • The jasper report function ABS will return a java.lang.Number, this is an abstract class that do not support any of the arithmetic or logic operator like +, -, <, >, <=

    The easiest way is to get the Integer or Double value from the Number (intValue(), doubleValue() see class methods)

    ABS($F{rop}-$V{Suggest_ROP}).intValue() >= 2