Jump to content
We've recently updated our Privacy Statement, available here ×

ClassCastException: java.math.BigDecimal


Recommended Posts

By: Yong Wang - wymz

ClassCastException: java.math.BigDecimal

2002-11-19 14:48

Hi I am getting this cast exception at runtime:

 

Caught exception: Error evaluating expression estimated value : variable_StatusGroup_TOTAL

java.lang.ClassCastException: java.math.BigDecimal at jsinventory2grp.evaluateEstimated(jsinventory2grp.java:552) at dori.jasper.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:633) at dori.jasper.engine.fill.JRCalculator.estimateVariables(JRCalculator.java

...

here is the related portion of my jasper XML:

...

<field name="wholesale_price" class="java.lang.Double"/>

...

<variable name="StatusGroup_TOTAL" resetType="Group" resetGroup="StatusGroup" c

lass="java.lang.Double" calculation="Sum">

<variableExpression>$F{wholesale_price}</variableExpression>

</variable>

...

 

I would appreciate if someone can tell me what I am doing wrong. thanks.

 

 

 

By: Yong Wang - wymz

RE: ClassCastException: java.math.BigDecimal

2002-11-20 07:21

Thanks steve. You are right on the target. I didn't realize MySQL's decimal(10,2) gets translated into BigDecimal.

 

 

By: Steven Blough - stevenblough

RE: ClassCastException: java.math.BigDecimal

2002-11-20 04:23

Confirm that the field type coming from the database is a Double. By the error you are receiving I would guess that the database field is being returned as a BigDecimal not a Double. If you change the class types in your xml to BigDecimal that problem should be resolved.

 

Good Luck

 

Steven Blough

 

 

 

By: Yong Wang - wymz

RE: ClassCastException: java.math.BigDecimal

2002-11-20 13:04

This BigDecimal is still haunting me. I have a field "balance" defined as decimal( 10, 2) but I also have some SQL redefine "balance" at the selection as follows:

 

select if(isnull(balance), 0.00, balance) as balance ...

 

so what's happening now is the object in result set becomes Double.

 

I have to use Double as follows:

 

<field name="balance" class="java.lang.Double"/>

...

<variable name="InventoryGroup_balance" resetType="Group" resetGroup="Inventory

Group" class="java.lang.Double" calculation="Sum">

...

<textFieldExpression class="java.lang.Double">

$V{InventoryGroup_balance}

</textFieldExpression>

</textField>

...

<textFieldExpression class="java.lang.Double">$F{balance}</textFieldExpression>

...

 

at runtime, I am again getting cast exception:

 

Caught exception: Error evaluating expression value : variable_balance

java.lang.ClassCastException: java.lang.Double

at custlist.evaluate(custlist.java:332)

at dori.jasper.engine.fill.JRCalculator.evaluate(JRCalculator.java:656)

...

 

I tried to switch to BigDecimal, still getting cast exception (at different location?):

 

Caught exception: Error evaluating expression value : variable_balance

java.lang.ClassCastException: java.lang.Double

at custlist.evaluate(custlist.java:367)

at dori.jasper.engine.fill.JRCalculator.evaluate(JRCalculator.java:656)

 

How do I get around this problem? where is the file "custlist.java"? thanks.

 

 

 

By: Teodor Danciu - teodord

RE: ClassCastException: java.math.BigDecimal

2002-11-23 02:35

 

Hi,

 

You probably have to cast the 0.00 value

to decimal(10, 2) in your SQL query.

 

I hope this helps.

Teodor

 

 

 

By: Yong Wang - wymz

RE: ClassCastException: java.math.BigDecimal

2002-11-20 14:11

This same problematic jasper XML works fine with embedded query and a database connection, but doesn't work with custom datasource. All this custom datasource (implements JRDataSource) does is use the same query string to get a ResultSet and return an object value from the current row for the JRField.

 

Another observation is embedded query and a database connection works even when jasper type doesn't match database type:

 

for example, I have "YEAR" defined as INT in database, but defined as "java.lang.String" in jasper, and it still works w/o exception. I suspect some data conversion is done in jasper for this case.

 

I would appreciate if someone could shed some light on my type cast problem. Thanks.

 

 

By: Yong Wang - wymz

RE: ClassCastException: java.math.BigDecimal

2002-11-21 10:00

Another observation is if the field does not involve in the variable calculation, the conversion from BigDecimal to Double is automatic, no exception.

I really need some help with the problem I posted at 2002-11-20 16:04. Thanks!

 

 

By: Yong Wang - wymz

RE: ClassCastException: java.math.BigDecimal

2002-11-21 11:17

I have figured out my problem. But I am still unclear about the following two items:

 

1) the different behavior btw custom datasource and embedded sql with a connection. The field type is much relaxed in the latter.

 

2) with custom datasource, those fields involved in variable calculation must have exact java type as returned by datasource while no such requirement for other fields.

 

 

 

By: Teodor Danciu - teodord

RE: ClassCastException: java.math.BigDecimal

2002-11-23 02:31

 

Hi,

 

Why don't you just take a look at the source code

of the JRResultSetDataSource class to see why

it works and your implementation does not?

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...