简体   繁体   中英

JRException: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

I have an error using Jaspersoft Studio with Oracle Database. As soon as there is some data, the following line

<printWhenExpression><![CDATA[$P{REPORT_TYPE}.substring(0,1)=="R"? $F{REASON_DELETED}:$F{REASON_ADOC}]]></printWhenExpression>

throws the following error:

net.sf.jasperreports.engine.JRException: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

I don't understand, why Jasper Studio would cast it to a Boolean, since it is defined as a String:

<field name="REASON_ADOC" class="java.lang.String"/>
<field name="REASON_DELETED" class="java.lang.String"/>

and the SQL is also fine to me:

NVL(cr.REASON_ADHOC,'-') AS reason_adoc,
NVL(cr.REASON_DELETED,'-') AS reason_deleted,

and also in the view/table:

REASON_DELETED  VARCHAR2(250)
REASON_ADHOC    VARCHAR2(4000)

You're right, your expression returns a String. But printWhenExpression expects boolean expression as a content. According to docs :

printWhenExpression Definition of a Boolean expression that will determine if the element or the band should be printed or not.

It's not clear what are you trying to achieve. You might want to use textFieldExpression instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM