JasperReports:获取java.lang.IllegalArgumentException:name

时间:2012-10-18 10:52:01

标签: java jasper-reports glassfish-3

我目前正在开发一个包含jasper报告,netbeans 7.1.1和Glassfish服务器的项目。似乎带有图像的报告在Jasper上成功运行,但是当我在我的Web应用程序中运行时,异常被抛出为java.lang.IllegalArgumentException: name

SEVERE: java.lang.IllegalArgumentException: name
at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:460)
at sun.misc.URLClassPath.findResource(URLClassPath.java:146)
at java.net.URLClassLoader$2.run(URLClassLoader.java:385)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:382)
at java.lang.ClassLoader.getResource(ClassLoader.java:1003)
at java.lang.ClassLoader.getResource(ClassLoader.java:998)
at com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader.getResource(APIClassLoaderServiceImpl.java:205)
at java.lang.ClassLoader.getResource(ClassLoader.java:998)
at java.lang.ClassLoader.getResource(ClassLoader.java:998)
at org.glassfish.web.loader.WebappClassLoader.getResource(WebappClassLoader.java:1153)
at net.sf.jasperreports.engine.util.JRResourcesUtil.findClassLoaderResource(JRResourcesUtil.java:473)
at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:464)
at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:176)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:944)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:891)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:256)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:482)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2011)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillGroupHeader(JRVerticalFiller.java:603)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillGroupHeaders(JRVerticalFiller.java:523)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:250)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:110)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:923)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:826)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:59)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)
at net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:203)
at org.serv.ReportServlet.generateReport(ReportServlet.java:142)
at org.serv.ReportServlet.doPost(ReportServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)

任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)

使用try / catch块将调用包装到ClasssLoader上的getResource:

URL url = null;
try {
    url = loader.getResource(fileName);
} catch (final Exception e) {
}

在该语句之后,检查url是否为空值,如果它为null,则您已尝试创建 fileName java.io.File对象。也许这是一个更好的解决方案,首先检查传递的fileName是否是一个有效的文件,如果它不是现有文件,只询问ClassLoader一个URL。