dayv2005 Posted December 23, 2011 Share Posted December 23, 2011 I am having a problem. I have a field that would look something like this "test 1;Test 2;;;" where it holds 5 values. I understand it's bad design but this is some legacy stuff I'm trying to interface with. It will always be 5 values. I created 5 varibles of string type. var1,var2, and so on.var1 expression looks like this...( $F{MaintOptionDesc}.split(";")[0] == null ? "BLANK" : "NOT BLANK" )as long as the string is like this "test1;;;;" it works and doesn't error out. But if the string is ";;;;" it errors out. How can i modify this epression to handle no values. Code:Error filling print... Error evaluating expression :     Source text : ( $F{MaintOptionDesc}.split(";")[0].toString() == null ? "BLANK" : "NOT BLANK" ) For input string: "" net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :     Source text : ( $F{MaintOptionDesc}.split(";")[0].toString() == null ? "BLANK" : "NOT BLANK" )     at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:259)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:580)     at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:179)     at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:789)     at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1478)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:125)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:942)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:877)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: java.lang.ArrayIndexOutOfBoundsException: 0     at org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(DefaultGroovyMethods.java:2960)     at sun.reflect.GeneratedMethodAccessor153.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:51)     at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:754)     at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:765)     at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:753)     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)     at leaseVsOwnF_1324659072367_973109.evaluateEstimated(calculator_leaseVsOwnF_1324659072367_973109:773)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:246)     ... 13 more Link to comment Share on other sites More sharing options...
mwatkinson Posted January 25, 2012 Share Posted January 25, 2012 The problem with the following statement: ( $F{MaintOptionDesc}.split(";")[0] == null ? "BLANK" : "NOT BLANK" )when MaintOptionDesc = ";;;;;" is that there are no values to return and the array from the split operation is of size 0. Since there is no check for this error, you recieve a java exception when it attempts to execute with a 'blank' input.For this to work when input is blank you will need an additional check: ( $F{MaintOptionDesc}.split(";").size() == 0 ? "BLANK" : "NOT BLANK" )Once you have that you can extend it to get each of your values: ( $F{MaintOptionDesc}.split(";").size() > 0 ? "BLANK" : $F{MaintOptionDesc}.split(";")[0] ) ( $F{MaintOptionDesc}.split(";").size() > 1 ? "BLANK" : $F{MaintOptionDesc}.split(";")[1] ) ... ( $F{MaintOptionDesc}.split(";").size() > 4 ? "BLANK" : $F{MaintOptionDesc}.split(";")[4] ) I think this will give you want you want. 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