为什么在调用 JasperFillManager 时会在 java.lang.Class.isAssignableFrom(Native Method) 处得到 java.lang.NullPointerException?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7776968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:23:49  来源:igfitidea点击:

Why do I get java.lang.NullPointerException at java.lang.Class.isAssignableFrom(Native Method) when calling JasperFillManager?

javanullpointerexceptionjasper-reports

提问by JN_newbie

JasperFillManager is throwing a null pointer exception when I pass sql connection in its parameter but it runs fine when I pass JRResultSetDatasource.

当我在其参数中传递 sql 连接时,JasperFillManager 抛出一个空指针异常,但当我传递 JRResultSetDatasource 时它运行良好。

java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at net.sf.jasperreports.engine.fill.JRFillTextField.getFormat(JRFillTextField.java:706)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:394)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:368)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:258)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:499)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2036)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:760)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:270)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:609)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205)
at java.lang.Thread.run(Unknown Source)

when I pass connection in fillReport it gives exception.

当我在 fillReport 中传递连接时,它给出了异常。

jasperPrint = JasperFillManager.fillReport(jasperReport, map, reportConnection);

I am also using a subreport so that is why I am not using JRResultSetDatasource and using connection. I am just stuck into this note that when I pass JRResultSetDatasource it works fine and when I also pass connection object in a HasMap parameter it gives same error as above.

我也在使用子报表,所以这就是为什么我不使用 JRResultSetDatasource 和使用连接。我只是被困在这个注释中,当我传递 JRResultSetDatasource 时它工作正常,当我还在 HasMap 参数中传递连接对象时,它会给出与上面相同的错误。

回答by Juan Rada

I just fixed this two minutes ago updating my iReport jar file to the last version

我刚在两分钟前解决了这个问题,将我的 iReport jar 文件更新到了最新版本

回答by ssk

Your jasper-designer and jar in your project should be the same version.

您项目中的 jasper-designer 和 jar 应该是相同的版本。

回答by AhmadNasrElKaffas

The Jar files in the projects lib folder should be matching the version of iReport I had the same problem and it has been solved by using correct jar files. you can take a look at the link below: http://sourceforge.net/projects/jasperreports/files/jasperreports/

项目 lib 文件夹中的 Jar 文件应该与 iReport 的版本相匹配我遇到了同样的问题,并且已通过使用正确的 jar 文件解决了这个问题。你可以看看下面的链接:http: //sourceforge.net/projects/jasperreports/files/jasperreports/

回答by Azhaguvel A

There is no an issue to replace from old .jar to new .jar. If you have an option. Suppose you need to maintain the old jar but it should work means. Please use this.

从旧的 .jar 替换为新的 .jar 没有问题。如果你有一个选择。假设您需要维护旧罐子,但它应该可以工作。请使用这个。

The following code works in higher version [Ex: 4.1.1] not in older version [Ex: 3.7.6].

以下代码适用于更高版本 [Ex: 4.1.1] 而不是旧版本 [Ex: 3.7.6]。

 <subreport>
       <reportElement positionType="Float" x="335" y="25" width="175"
                height="20" isRemoveLineWhenBlank="true"
                backcolor="#99ccff"/>

                <dataSourceExpression>
                new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
                ($F{subReportBeanList})
                </dataSourceExpression>
                <subreportExpression class="java.lang.String">
                   <![CDATA[$P{SUBREPORT_DIR} + "subReport.jasper"]]>
                </subreportExpression>
   </subreport>

The same code works in older version with little bit modification.

相同的代码在稍加修改的旧版本中也能工作。

<parameter name="subreportParameter" class="net.sf.jasperreports.engine.JasperReport"/>
    <subreport>
       <reportElement  positionType="Float" x="1" y="2" width="532" height="15" isRemoveLineWhenBlank="true" backcolor="#99CCFF"/>
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
                ($F{subReportBeanList})]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{subreportParameter}]]></subreportExpression>
                </subreport>