jimmo Posted October 11, 2010 Share Posted October 11, 2010 Hi All!I am an iReport and Java newbie. I would like to display text depending on whether an integer is 0 or 1. (The field is defined as a NUMBE, although it is actually used as a boolean). What I would like to do is something like this:$F{afgemeld}.equals(1)?"Yes":"No"In the error output I getSource text : $F{afgemeld}.equals(1)?"Yes":"No"net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Then a few lines later:Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'No' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:127) I understand it so far that iReport cannot cast a string to an interger, so I was trying to cast the original value "afgemeld" to a string. That is where I am getting stuck. I tired this:$F{afgemeld}.toString().equals("0")?"Yes":"No"This also gives me:Cannot cast object 'No' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:127) Can someone give me a kick in the right direction? I would be very grateful! Link to comment Share on other sites More sharing options...
svenn Posted October 12, 2010 Share Posted October 12, 2010 $F{afgemeld} ==1 ?"Yes":"No" Link to comment Share on other sites More sharing options...
hangman01 Posted October 12, 2010 Share Posted October 12, 2010 I am not sure that this would actually be considered a kick in the right direction or not but for one thing your report is using groovy and not java. You need to either use groovy in your expression or switch the report properties to Java for the language. If you switch to Java the expression will need to be something like:$F{afgemeld}.intValue()==1?"Yes":"No"I do not know any groovy so I can not help you if you go that direction. You will notice that as you create new reports iReport defaults to language=groovy and you must remember to make that change to use Java. I hope that this helps you. Link to comment Share on other sites More sharing options...
jimmo Posted October 13, 2010 Author Share Posted October 13, 2010 $F{afgemeld}==1?"Yes":"No"returnsError filling print... Error evaluating expression :Source text : $F{afgemeld}==1?”Yes”:”No”net. sf. jasperreports. engine. fill. JPExpressionEvalException: Error evaluating expression :Source text : ^$F{afgemeld}==1?’Yes’:”No”...Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Yes' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:127) Link to comment Share on other sites More sharing options...
jimmo Posted October 13, 2010 Author Share Posted October 13, 2010 I learned something, so it is always a good thing. Switched the report language to Java (also learned how to do that!). However, now I am getting "Cannot cast from String to BigDecimal". Link to comment Share on other sites More sharing options...
hangman01 Posted October 14, 2010 Share Posted October 14, 2010 My guess would be that you need to set the properties of the text_field from "java.math.BigDecimal" to "java.lang.String". Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now