{"id":2730,"date":"2022-08-30T15:27:18","date_gmt":"2022-08-30T15:27:18","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/08\/java-jasper-report-nullpointerexception-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:27:18","modified_gmt":"2022-08-30T15:27:18","slug":"java-jasper-report-nullpointerexception-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/java-jasper-report-nullpointerexception-collection-of-common-programming-errors\/","title":{"rendered":"Java jasper report NullPointerException-Collection of common programming errors"},"content":{"rendered":"<p>I am new to Java and I am running into this issue that I can&#8217;t figure out. I inherited this project and I have the following code in one of my scriptlets:<\/p>\n<pre><code>DefaultLogger.logMessage(\"DEBUG path: \"+ reportFile.getPath());\nDefaultLogger.logMessage(\"DEBUG parameters: \"+ parameters);\nDefaultLogger.logMessage(\"DEBUG jr: \"+ jr);\nbytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, jr);\n<\/code><\/pre>\n<p>And I am getting the following results (the fourth line there is line 287 in FootwearReportsServlet.doGet):<\/p>\n<pre><code>DEBUG path: C:\\Development\\JavaWorkspaces\\Workspace1\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\RSLDevelopmentStandard\\reports\\templates\\footwear\\RslFootwearReport.jasper\nDEBUG parameters: {class_list_subreport=net.sf.jasperreports.engine.JasperReport@b07af1, signature_path=images\/logo_reports.jpg, submission_id=20070213154168780, test_results_subreport=net.sf.jasperreports.engine.JasperReport@5795ce, logo_path=images\/logos_3.gif, report_connection_secondary=com.mysql.jdbc.JDBC4Connection@2c39d2, testing_packages_subreport=net.sf.jasperreports.engine.JasperReport@1883d5f, signature_path2=images\/logo_reports.jpg, tpid_subreport=net.sf.jasperreports.engine.JasperReport@17531fd, first_page_subreport=net.sf.jasperreports.engine.JasperReport@12504e0}\nDEBUG jr: net.sf.jasperreports.engine.data.JRMapCollectionDataSource@1630eb6\nApr 29, 2010 4:15:13 PM org.apache.catalina.core.StandardWrapperValve invoke\nSEVERE: Servlet.service() for servlet FootwearReportsServlet threw exception\njava.lang.NullPointerException\n    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)\n    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)\n    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517)\n    at net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:385)\n    at com.rsl.reports.FootwearReportsServlet.doGet(FootwearReportsServlet.java:287)\n    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)\n    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)\n    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)\n    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)\n    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)\n    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)\n    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)\n    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)\n    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)\n    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)\n    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)\n    at java.lang.Thread.run(Unknown Source)\n<\/code><\/pre>\n<p>What I can&#8217;t figure out is where the null reference is. From the debug lines I can see that each parameter has a value. Could it be referring to a bad path to one of the images? Any ideas? For some reason my server won&#8217;t start in debug mode in Eclipse so I am having trouble figuring this out.<\/p>\n<ol>\n<li>\n<p>From looking at the line where you are getting the error:<\/p>\n<pre><code>jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)\n<\/code><\/pre>\n<p>In the JRFiller source code it corresponds to<\/p>\n<pre><code>jasperPrint = filler.fill(parameters, dataSource);\n<\/code><\/pre>\n<p>The only thing that can cause a <code>NullPointerException<\/code> in this line is the case when <code>filler<\/code> is <code>null<\/code>. The parameters are not checked for <code>null<\/code> at this point.<\/p>\n<p>Looking at the code of <code>createFiller<\/code> (line 134), you can easily see the condition in which that function returns a null pointer. So I guess you somehow forgot to specify the print order (<code>PRINT_ORDER_HORIZONTAL<\/code> or <code>PRINT_ORDER_VERTICAL<\/code>).<\/p>\n<\/li>\n<li>\n<p>I have got the same problem.<\/p>\n<p>Roland Illig is right, the print order is missing. This might be because the compiled report file is missing required fields.<\/p>\n<p>Adding a value to the print order field afterwards does not help, it just keeps crashing at the next position where another field is missing.<\/p>\n<p>Use the same version of the compiler (for example iReport) and your runtime library.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-08 03:40:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am new to Java and I am running into this issue that I can&#8217;t figure out. I inherited this project and I have the following code in one of my scriptlets: DefaultLogger.logMessage(&#8220;DEBUG path: &#8220;+ reportFile.getPath()); DefaultLogger.logMessage(&#8220;DEBUG parameters: &#8220;+ parameters); DefaultLogger.logMessage(&#8220;DEBUG jr: &#8220;+ jr); bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, jr); And I am getting the following [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2730","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2730"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2730\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}