java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal

Hi ,


  I am having report1 and report2 , When I declare field

field name="Total " class="java.math.BigDecimal"

In report1, report2 and In report2,I am declare a variable as below

        variable name="sum_N_1" class="java.lang.BigDecimal" resetType="Group" resetGroup="report1" calculation="Sum"
        variableExpression  ![CDATA[$F{Total }]]  /variableExpression
        initialValueExpression   ![CDATA[0]]  /initialValueExpression


I am getting exception when I run report2 as fallows 


2013-03-13 21:11:14,103 ERROR JRFillSubreport,http-8080-1:742 - Fill 1: exception
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigDecimal
        at net.sf.jasperreports.engine.fill.JRBigDecimalSumIncrementer.increment(
        at net.sf.jasperreports.engine.fill.JRAbstractExtendedIncrementer.increment(
        at net.sf.jasperreports.engine.fill.JRCalculator.calculateVariables(
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(
        at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(
        at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(


If I change to         variable name="sum_N_1" class="java.lang.Integer" resetType="Group" resetGroup="report1" calculation="Sum"  ,   I am able to run the report, I am not understand why the exception is coming.

Please help me ..




rsuddhala's picture
Joined: Aug 16 2012 - 10:55pm
Last seen: 4 years 7 months ago

1 Answer:

I would change your initialValueExpression to BigDecimal.valueOf(0)

bobtins's picture
Joined: Aug 17 2006 - 5:03pm
Last seen: 3 years 6 months ago

Thank you bobtins,Now I am able to run report..Thanks you very much..

rsuddhala - 10 years 2 weeks ago

Thank you for the solution

freelog3107 - 8 years 4 months ago

Thank you so much, this was killing me for hours, couldn't even pinpoint that the problem was in the variables

zilex - 5 years 9 months ago
show 2 more...

Thanks... even after almost 7 years.. this solved my problem..

MicAre - 3 years 6 months ago

This worked for me after many hours not finding any hint of what could be causig this error - many thanks.

hondaman900 - 2 years 4 months ago