我目前正在将 JasperReports 库从版本 6.0.4 升级到 7.0.0。我的系统当前正在使用以下 JasperReports 库:
升级这些库及其依赖项和其他 JasperReports 库后:
尝试下载报告 (PDF) 时系统抛出错误。我的系统使用 Java Servlet。
系统错误:
ERROR http-nio-8080-exec-3 OCSASTDFP :: [O00045.java:281] :: net.sf.jasperreports.engine.JRException: Unable to load report
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:149)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:136)
...
Tomcat 错误:
org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler - Exception occurred during processing request: Cannot invoke "java.io.PrintWriter.print(String)" because "this.pw" is null
java.lang.NullPointerException: Cannot invoke "java.io.PrintWriter.print(String)" because "this.pw" is null
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at ognl.OgnlRuntime.invokeMethodInsideSandbox(OgnlRuntime.java:1245) ~[ognl-3.3.3.jar:?]
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:1230) ~[ognl-3.3.3.jar:?]
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1958) ~[ognl-3.3.3.jar:?]
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) ~[ognl-3.3.3.jar:?]
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:98) ~[struts2-core-6.0.3.jar:6.0.3]
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:90) ~[struts2-core-6.0.3.jar:6.0.3]
我尝试遵循 StackOverflow 和 Jasper 社区的一些建议,包括添加:
但是,这个问题仍然存在。
我在升级到 JasperReports 7.0.1时遇到了同样的问题。我通过将
jasperreports-excel-poi
依赖项添加到我的项目中解决了这个问题。
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-excel-poi</artifactId>
<version>7.0.1</version>
</dependency>