Jump to content

Recommended Posts

Posted

Hi, I'm new to iReport and I've been trying to use "Print when expression"  to change the value of a field in the database from 0 or 1 (I use MySQL, so no boolean) to Yes No. I've searched around but none of the solutions seems to be working for me. No matter what I try, I always get the same error at compile time : Error filling print... java.lang.String cannot be cast to java.lang.Boolean

Integer.parseInt($F{myFieldName}) == 1 ? "Yes" : "No"

I've tried various ways to do the comparison, including converting both operands to String or whatever. Fun thing, my comparison seems to "work", as in if I don't put in the if, my report compiles without problem but as soon as I add it the error shows up.

I've also made sure my field type (Expression class) is set to java.lang.String

Thanks.

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

"Print when expression" used in JR expects a boolean value return - it has nothing to do with the class type of the field you are trying to evaluate:

Integer.parseInt($F{myFieldName}) == 1?true:false

You can simply put

Integer.parseInt($F{myFieldName}) == 1

in the print when expression. If it's true, it will print out the element.

Posted

I see...

And If I would like to control what appears in my Field based on a conditon, where should that be put if its not in Print when Expression ?

 

EDIT: I found it a couple of minutes after, I needed to put the condition directly in the Expression field. Thanks for pointing me the right way ! 

 

  • 4 years later...
Posted

EDIT: I found it a couple of minutes after, I needed to put the condition directly in the Expression field. Thanks for pointing me the right way ! 

what do u mean?

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...