Java – Expression Value in Jasper Report: “Cannot cast from String to Boolean” error


This is my expression code:

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

If Personel is paid, her/his Jasper tax report will read PAID, otherwise NO PAID. In the DB, this field is Boolean type, but the expression is returning a String type. So I am getting a Cannot cast from String to Boolean error.

Best Solution

The problem stems from your test $F{Personel_ODEME}.equals(Boolean.TRUE), which Jasper is thinking is a String to Boolean comparison, and doesnt like. To fix this, try this:

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

This will result in a String to String comparison.

It is good to note that In Java, a "true".equals(Boolean.TRUE) would result to false.


This appears to be a Jasper 'PrintWhen' expression, which allows you to determine whether to print the contents of a cell or not. It is expecting Boolean.TRUE or Boolean.FALSE as its return values. When you return "PAID", Jasper tries to evaluate that String as a Boolean, which it cant, so it throws the exception.