Case1182 Posted May 8, 2007 Share Posted May 8, 2007 I have not been able to find a working count function in iReports, have tried different formats of java, sql, and grping in iReports. Want to count all the strings match x in y column. Any suggestions let me know. Link to comment Share on other sites More sharing options...
svenn Posted May 8, 2007 Share Posted May 8, 2007 Set up a variable and use a condition and the count function. You can rest the variable value so try resetting it at various points until you get the result that you are looking for. Link to comment Share on other sites More sharing options...
Case1182 Posted May 9, 2007 Author Share Posted May 9, 2007 Gives me an error everytime, "cannot cast boolean as Boolean" and "cannot cast int as Integer" Link to comment Share on other sites More sharing options...
svenn Posted May 9, 2007 Share Posted May 9, 2007 Please post your code. Don't post the whole jrxml file, just post the text that you have in the variable expession. Link to comment Share on other sites More sharing options...
Case1182 Posted May 9, 2007 Author Share Posted May 9, 2007 I have tried over 30 variations of suggested expressions, can you suggest a expression to use? Link to comment Share on other sites More sharing options...
jmurray Posted May 9, 2007 Share Posted May 9, 2007 You have to imagine your expressions as being an inline piece of Java (because that's what they will be when the xml is interpreted by the report engine!). All of the expression boxes will resolve to a specific java class (eg. java.lang.String or java.lang.Integer or java.util.Date) as specified by you. Your raw expressions will always result in a primitive such as string, integer, or boolean. The construct for a primitive does not match the construct for a class, so you'll always end up with an exception. So you need to recast as part of your expression. Let's say you have an expression box that expects a java.lang.Boolean to be returned. If you enter an expression like this: $V{REPORT_COUNT}.intValue>1 then the result will be boolean and you'll get an exception because boolean != Boolean. You need to wrap it in a cast to Integer like this: new java.lang.Boolean($V{REPORT_COUNT}.intValue>1) Link to comment Share on other sites More sharing options...
Case1182 Posted May 9, 2007 Author Share Posted May 9, 2007 I am trying to do something like this: If ($F{NAME}.toString() == $P{NAME}.toString()){$F{COUNT}.toString() = $F{COUNT}.toString() + 1} It will not except the full java statement, does not recongize things like ELSE, it says this is fine but when I go to execute it gives this error. it.businesslogic.ireport.gui.logpane.ProblemItem@186b73e Syntax error, insert ")" to complete Expression Line 262, Column 53 /jasperReport/title[1]/band[1]/textField[4]/textFieldExpression[1]it.businesslogic.ireport.gui.logpane.ProblemItem@1687b84 Syntax error, insert ";" to complete BlockStatements Line 262, Column 53 /jasperReport/title[1]/band[1]/textField[4]/textFieldExpression[1]it.businesslogic.ireport.gui.logpane.ProblemItem@855040 Syntax error on tokens, delete these tokens Line 262, Column 53 /jasperReport/title[1]/band[1]/textField[4]/textFieldExpression[1]it.businesslogic.ireport.gui.logpane.ProblemItem@57b4b0 Syntax error, insert "}" to complete Block it.businesslogic.ireport.gui.logpane.ProblemItem@179d59 Syntax error, insert "}" to complete Block it.businesslogic.ireport.gui.logpane.ProblemItem@5b5ff5 Syntax error, insert "}" to complete Block Link to comment Share on other sites More sharing options...
jmurray Posted May 10, 2007 Share Posted May 10, 2007 duplicate post removed Post edited by: jmurray, at: 2007/05/09 23:13 Link to comment Share on other sites More sharing options...
jmurray Posted May 10, 2007 Share Posted May 10, 2007 Lots of issues here: First, you can't use If..Then..Else..Endif. You have to use ( comparison ? action when true : action when false ) Next up $F{NAME} and $P{NAME} are likely to be Strings already so there's no need to perform a .toString on them. It is very bad karma to perform a String==String comparison. Use .equals() instead. You can't change the value of a field, so trying to increment $F{COUNT} won't work. Use a variable instead. Using reserved words like NAME and COUNT as variable, field or parameter names is asking for trouble. -------------------- The solution is to set up a java.lang.Integer variable called $V{myCOUNT} with an Initial Value Expression of new java.lang.Integer(0) and a Calculation Type of "Sum". Then set your Variable Expression to new java.lang.Integer($F{NAME}.equals($P{NAME} ? 1 : 0 ). This will increment $V{myCOUNT} whenever the contents of $F{NAME} match the contents of $P{NAME} otherwise do nothing. .Post edited by: jmurray, at: 2007/05/09 23:13 Link to comment Share on other sites More sharing options...
Case1182 Posted May 10, 2007 Author Share Posted May 10, 2007 Did like u said and i am getting this error Type mismatch: cannot convert from String to booleanLine 54, Column 23 /jasperReport/variable[1]/variableExpression[1] Link to comment Share on other sites More sharing options...
Case1182 Posted May 10, 2007 Author Share Posted May 10, 2007 Got it to work like this except it doesnt increment the value. new java.lang.Integer($F{NAME}.toString() + "%" == $P{NAME}.toString() ? $V{myCOUNT}.intValue() + 1 : $V{myCOUNT}.intValue() + 0 ) the "%" is because it is a oracle database and requires it at the end of the parameter. any ideas????? Link to comment Share on other sites More sharing options...
jmurray Posted May 14, 2007 Share Posted May 14, 2007 Yes, there was a typo in my posting! Bugger. The Variable Expression was missing a closing parenthesis, so enter this instead: new java.lang.Integer($F{NAME}.equals( $P{NAME} ) ? 1 : 0 ) Everything else stays the same. You must stop using "==" to compare Strings. Very, very much badness. Link to comment Share on other sites More sharing options...
martynhiemstra Posted August 10, 2007 Share Posted August 10, 2007 Using == to compare strings isnt badness its just plain stupid. It will almost always return false because you are comparing memory locations and not the string contents Link to comment Share on other sites More sharing options...
boywth Posted August 29, 2007 Share Posted August 29, 2007 thank you everybody!I am from China.I am study Ireport and Jasperreport.my msn:wth33@msn.comwelcome you ! Link to comment Share on other sites More sharing options...
vinayatheja Posted November 17, 2008 Share Posted November 17, 2008 hi,this is vinay, i have a problem of converting numbers to words in ireport. if there any solution plese help me .. give me the solution to vinayatheja@gmail.com Link to comment Share on other sites More sharing options...
sukeshpvs Posted March 8, 2012 Share Posted March 8, 2012 Post Edited by sukeshpvs at 03/08/2012 05:21 Link to comment Share on other sites More sharing options...
data_man Posted June 8, 2012 Share Posted June 8, 2012 I realize this is an old post, but this was really helpful. Thanks! Link to comment Share on other sites More sharing options...
shippu4u Posted September 11, 2012 Share Posted September 11, 2012 The below mentioned solution worked for me but keep in mind that uou have to set the resest type of variable to " Report"The solution is to set up a java.lang.Integer variable called $V{myCOUNT} with an Initial Value Expression of new java.lang.Integer(0) and a Calculation Type of "Sum".Then set your Variable Expression to new java.lang.Integer($F{NAME}.equals($P{NAME} ? 1 : 0 ). This will increment $V{myCOUNT} whenever the contents of $F{NAME} match the contents of $P{NAME} otherwise do nothing. 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