The value of the expression in the Jasper report: "Cannot drop from string in Boolean" error

This is my expression code:

($F{Personel_ODEME}.equals(Boolean.TRUE)) ? "PAID" : "NO PAID" 

If the character is paid, his Jasper tax return report will read PAID , otherwise NO PAID . In the database, this field is of type Boolean, but the expression returns a type of String. Therefore, I get the Cannot cast from String to Boolean error.

+4
source share
5 answers

OK, I fixed it. I changed the type of $F{Personel_ODEME} to String, then it worked like a charm.

+3
source

The problem is with your test $F{Personel_ODEME}.equals(Boolean.TRUE) , which, according to Jasper, is a String to Boolean comparison and doesn't like it. To fix this, try the following:

 ($F{Personel_ODEME}.equals(Boolean.TRUE.toString())) ? "PAID" : "NO PAID" 

This will result in a comparison from String to String .

It’s good to note that in Java a "true".equals(Boolean.TRUE) will result in false.

edit:

This is apparently Jasper's β€œPrintWhen” expression, which allows you to determine whether to print the contents of a cell or not. Boolean.TRUE or Boolean.FALSE is expected as return values. When you return "PAID", Jasper tries to evaluate that String as a Boolean , which it cannot, so it throws an exception.

+10
source

You must change the class expression for this field to java.lang.String, because by default it will be java.lang.Boolean. When it evaluates your if and tries to return "PAID" or "NO PAID", the field tries to convert it to Boolean so that it displays.

Credit:

http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=61775

+2
source

Try the following:

 Boolean.valueOf($F{Personel_ODEME}.equals('TRUE')) ? "PAID" : "NO PAID" 
+1
source
 ($F{Personel_ODEME}==true?"PAID":"NO PAID") 

Note. True (keyword) is case sensitive. And should not be capital (TRUE)

0
source

All Articles