I inherited a project from a developer that left the company. The project is in java (new to me) and uses jasper reports (new to me) to generate a PDF. I need to update one of the reports to remove some text. If I get the code out of source control and just run it it works fine. But if I open one of the jrxml files and build it making no changes then try to run the report again it breaks. The error I'm getting is:
java.lang.NullPointerException java.lang.Class.isAssignableFrom(Native Method) net.sf.jasperreports.engine.fill.JRFillTextField.getFormat(JRFillTextField.java:706) net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:394) net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:368) net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:258) net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:499) net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2036) net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:760) net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:270) net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946) net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845) net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:609) net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59) net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205) java.lang.Thread.run(Unknown Source)
I can't for the life of me figure out what the error means or how to debug it. As I said above I made no changes to the actual report. All I did at this time was open the jrxml file in iReport and build it. If I revert the jasper file to the version that was checked in then the report starts working again. This report has some sub reports and it doesn't seem to matter which file I build any one will break the whole report.
I don't know if it helps but I debugged the code and the line it's dying on reads:
bytes = JasperRunManager.runReportToPdf(...)
EDIT: My jasper report JAR and my iReport version were different versions. I added the JAR for the version of iRpeort I'm using (5.1.0) and I'm getting a new error now. Progress! The error is:
cannot assign instance of net.sf.jasperreports.engine.base.JRBaseTextField to field net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type net.sf.jasperreports.engine.JRParagraphContainer in instance of net.sf.jasperreports.engine.base.JRBaseParagraph
Thanks for the help commenters. I just went and got iReport v4.0.1 to match the Jar I had. Now I can edit the files. Unfortunately I don't have the time to go and learn all this from scratch so I'll just sick with the older version for now.
NullPointerException
means some object reference is pointing tonull
and the code is trying to call a method or access a field on that object reference. Make sure everything in(...)
is initialized, ie. not null. – Sotirios DelimanolisJRFillTextField.getFormat
returnsnull
. Then some internal method callsClass.isAssignableFrom
on that Format, which throwsNullPointerException
. – Sotirios Delimanolis