help with expression

Hi, I'm trying to create a report where I get an Integer describing the role of a family member.

I'm trying to print it using the following expression:

($F{Role}.intValue() == 1) ?"Father":"Mother"

but I get always the following error message when I try to run the report:

Cannot Cast from String to Integer

What can be done? I've tried of lot of things but nothing seems to work.
ehasbun's picture
12
Joined: Jul 3 2008 - 11:47pm
Last seen: 15 years 2 months ago

3 Answers:

Hi,

Check the field class of your field "Role". You should be abble to change it to integer. Then you can delete the ".intValue" part.

Then check the expression class of your text field - should be string.
Pethrus's picture
152
Joined: Jul 3 2008 - 1:24am
Last seen: 15 years 2 months ago
Hi,
When I look at the field, it says it is an Integer. How could I convert it to an Integer? Do you have a similar example?
ehasbun's picture
12
Joined: Jul 3 2008 - 11:47pm
Last seen: 15 years 2 months ago
The type of $F{Role} needs to remain in Integer. Keep the exact expression you have, but change the type of the expression to String. If you are working in iReport and you created this textfield by dragging it into the report design, iReport will create a textfield with the fields type by default. But your expression returns a string so you need to update the textfield type to reflect this.

Hope this helps.
lshannon's picture
2648
Joined: Feb 2 2007 - 3:54am
Last seen: 9 years 6 months ago
Feedback