2
votes

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.

1
A NullPointerException means some object reference is pointing to null 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 Delimanolis
None of the parameters are null but one parameter is a hashmap with null items in it. It works if I use the checked in .jasper file though which leads me to believe the calling code is working but maybe I'm wrong.William
The actual problem (from what I can tell) is that you have a text field with an unset Format (in your jrxml) and JRFillTextField.getFormat returns null. Then some internal method calls Class.isAssignableFrom on that Format, which throws NullPointerException.Sotirios Delimanolis
I was doing some looking online and noticed a comment that my jasperreports version and the ireport version need to be the same. My jasperreports jar is 4.0.1 and my iReport is 5.1.0. Could that be the issue? Trying to get the new jar in the project now and test.William
It can't hurt, but if the higher version jasperreports contains that same code, you will get the same exception.Sotirios Delimanolis

1 Answers

0
votes

Some features in the library changed going from 4 to 5, and it takes some tweaking to get the reports to work. One major change is with barcodes, how iReport includes them, and what library they are backed with. Because you are not familiar with java or JasperReports, I think that getting the older version of iReport was the right move.

In the future, know that it is possible to pack your JAR with the jrxml files instead of the compiled jasper files, and have the library compile the reports on the fly. This makes maintenance much less of a nightmare I have found.