Error when exporting jasper reports to pdf

852 views Asked by At

I am getting the error below when I try to export jasper report to pdf. Any help will be highly appreciated.

run:
Compiling Report Design ...
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The operator + is undefined for the argument type(s) Double, BigDecimal
                value = ((java.lang.Double)variable_TOTAL_CREDITS.getValue()) + ((java.math.BigDecimal)field_PREV_BAL.getValue()); //$JR_EXPR_ID=23$
                        <------------------------------------------------------------------------------------------------------->
2. The operator + is undefined for the argument type(s) Double, BigDecimal
                value = ((java.lang.Double)variable_TOTAL_CREDITS.getOldValue()) + ((java.math.BigDecimal)field_PREV_BAL.getOldValue()); //$JR_EXPR_ID=23$
                        <------------------------------------------------------------------------------------------------------------->
3. The operator + is undefined for the argument type(s) Double, BigDecimal
                value = ((java.lang.Double)variable_TOTAL_CREDITS.getEstimatedValue()) + ((java.math.BigDecimal)field_PREV_BAL.getValue()); //$JR_EXPR_ID=23$
                        <---------------------------------------------------------------------------------------------------------------->
3 errors
.
Done compiling!!! ...
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:215)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357)
    at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:273)
    at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:232)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:542)
    at writetofileexample.WriteToFileExample.main(WriteToFileExample.java:175)
BUILD SUCCESSFUL (total time: 2 seconds)
1

There are 1 answers

0
Paco Abato On

You must define the sums using double values instead of the Double and BigDecimal objects like:

variable_TOTAL_CREDITS.getValue().doubleValue() + field_PREV_BAL.getValue().doubleValue()

And if the operation may exceed the limits of double type you can use:

new BigDecimal(variable_TOTAL_CREDITS.getValue().doubleValue())
    .add((java.math.BigDecimal)field_PREV_BAL.getValue())