Hi, I want tom pass date as a field to the jrxml. Follwing is the code for it.
But it is not working. Its giving error as can not cast from date to number. Then how to convert it?
Hi, I want tom pass date as a field to the jrxml. Follwing is the code for it.
But it is not working. Its giving error as can not cast from date to number. Then how to convert it?
I cannot see the attached JRXML. However, open your JRXML file in a text editor, and check that the field is defined something like this:
<field name="MyDate" class="java.util.Date"/>
You are using the time
field in the constructor of Date
. No need for that.
Instead of this:
java.util.Date($F{time}.getTime())
use this:
$F{time}
If you want the long
value of it: then use this
$F{time}.getTime()
UPDATE
I didn't notice you are using a chart, here is a new answer:
In charts, X and Y value expressions should be any Number
object, check subclasses in Number Class JavaDoc, in your case you are getting the long
value of your Time
field, which cannot be cast to Number
, you will need to define a new object, for example:
new Long($F{time}.getTime())
Side Note: in this case the report will compile and work, BUT, you are getting the number of milliseconds and using it in your chart. I don't think that is what you want exactly. So i would suggest extracting a specific field from your Date
field like Day. Month, Year ... etc