Question

I want to format a date parameter in my report. The date looks like this in my database and my report "yyyy-mm-dd" (2014-04-17 for example). I tried to do it with that line of Code which I always saw on other posts:

new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum}) 

That doesn't work of course and I am getting this error:

Error filling print... Error evaluating expression :      Source text : new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum}) net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : new SimpleDateFormat("dd/MM/yyyy").format($P{Startdatum})     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)     at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:966)     at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:456)     at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:440)     at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)     at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:455)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:457)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)     at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)     at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)     at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: java.lang.IllegalArgumentException: Cannot format given Object as a Date     at java.text.DateFormat.format(DateFormat.java:301)     at java.text.Format.format(Format.java:157)     at Berichtsheft_1397742638211_397211.evaluate(Berichtsheft_1397742638211_397211:223)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)     ... 20 more Print not filled. Try to use an EmptyDataSource...

I am using this parameter for one of my Queries ! Could that be the reason for the error ? Or is the syntax simply false ? Or is there even any other reason for this error ?

Was it helpful?

Solution

Try to use just parameter name like this:-

  new SimpleDateFormat("dd/MM/yyyy").format($F{Startdatum})

and check the report "Language" in property panel you should change it to "java".

To change the report language go to Windows --> Report Inspector- and click on the report name and then --> Windows--> Properties.

Here in down the panel you can select the Language.

OTHER TIPS

Try to use that expression instead

new SimpleDateFormat("dd/MM/yyyy").parse($P{Startdatum})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top