创建Jasper报告时出现NullPointerExceptio

创建Jasper报告时出现NullPointerExceptio

本文介绍了创建Jasper报告时出现NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Liferay portlet中创建Jasper报告,但我收到以下错误

I am trying to create Jasper Report in Liferay portlet but I am getting below error

我的代码是:

String reportSource =D :/EMR/Dev/EMR-workspace/LMS/reports/HibernateQueryDemoReport.jrxml;

String reportDest =D:/EMR/Dev/EMR-workspace/LMS/reports/test_jasper.html;

My code is :
String reportSource = "D:/EMR/Dev/EMR-workspace/LMS/reports/HibernateQueryDemoReport.jrxml";
String reportDest = "D:/EMR/Dev/EMR-workspace/LMS/reports/test_jasper.html";

    try{
        JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
        JasperFillManager.fillReportToFile("D:/EMR/Dev/EMR-workspace/LMS/reports/DbReport.jasper",new HashMap(), connection);
        JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
        JasperViewer.viewReport(jasperPrint);
    }catch (JRException ex) {
        System.out.println(ex);
        }

我得到以下异常

java.lang.NullPointerException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
    at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:53)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.createDefaultRegistry(ExtensionsEnvironment.java:80)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.<clinit>(ExtensionsEnvironment.java:68)
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:77)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:87)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:52)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:199)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:95)
    at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.portlet.GenericPortlet.processAction(GenericPortlet.java:169)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ztscorp.lms.utils.AuthenticateFilter.doFilter(AuthenticateFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480)
    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
    at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
    at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)
    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:232)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:153)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:309)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:121)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:134)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:261)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:222)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.cache.CacheFilter.processFilter(CacheFilter.java:442)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:45)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:81)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:179)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)

06:12:20,717 ERROR [jsp] java.lang.NullPointerException
    at java.lang.Class.forName(Class.java:247)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
    at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
    at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:53)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.createDefaultRegistry(ExtensionsEnvironment.java:80)
    at net.sf.jasperreports.extensions.ExtensionsEnvironment.<clinit>(ExtensionsEnvironment.java:68)
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:77)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:87)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:52)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:199)
    at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:95)
    at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:102)
    at javax.portlet.GenericPortlet.processAction(GenericPortlet.java:169)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)


推荐答案

我得到了同样的错误(下面的堆栈)并通过删除修复了 default.jasperreports.properties src文件夹。

I got the same error (stack below) and fixed it by removing a default.jasperreports.properties that was in my src folder.

Exception in thread "main" java.lang.NullPointerException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
        at net.sf.jasperreports.engine.util.JRSingletonCache.createInstance(JRSingletonCache.java:84)
        at net.sf.jasperreports.engine.util.JRSingletonCache.getCachedInstance(JRSingletonCache.java:74)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1330)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1307)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:205)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:170)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:154)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:146)
        at com.cot.osppa.reports.OSPPAReportBuilder.main(OSPPAReportBuilder.java:74)

这篇关于创建Jasper报告时出现NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:23