我在netbeans中创建了一个项目,包括jasperreports,然后我将项目转换为jar文件。我想当我运行项目的jar文件jasperReports文件也工作正常.......但为此,我使用以下代码 来自代码的例外......
我尝试以下代码
//代码
InputStream input = this.getClass().getResourceAsStream("Users/Kashif/Desktop/Muhammad Kashif/Documents/NetBeansProjects/Torch/Reports/report11.jrxml");
JasperDesign jd = JRXmlLoader.load(input);
Map map = new HashMap();
map.put("Discount", para);
map.put("Customer", para1);
map.put("Total", para2);
JasperReport jasperReport = JasperCompileManager.compileReport(jd);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, con);
//view report to UI
JasperViewer.viewReport(jasperPrint, false);
//错误
net.sf.jasperreports.engine.JRException: java.net.MalformedURLException
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:305)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:284)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:273)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:247)
at torch.UserGui.printBtnActionPerformed(UserGui.java:1269)
.....
.....
.....
Caused by: java.net.MalformedURLException
at java.net.URL.<init>(URL.java:619)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1892)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:297)
... 42 more
Caused by: java.lang.NullPointerException
at java.net.URL.<init>(URL.java:524)
... 53 more
答案 0 :(得分:0)
由于缺少jrxml
文件,可能会出现异常。
你必须确保无论你在哪里部署你的JAR文件(不能清楚地理解),这个相对路径和文件(没有前面的斜杠!)都存在:
Users/Kashif/Desktop/Muhammad Kashif/Documents/NetBeansProjects/Torch/Reports/report11.jrxml
例如,如果您在主路径中的Linux服务器上部署,则必须确保
中有文件 /home/username/Users/Kashif/Desktop/Muhammad Kashif/Documents/NetBeansProjects/Torch/Reports/report11.jrxml
在Windows上,您必须确保文件位于目录结构下方,例如
C:\mypath\java -jar xyz.jar
C:\mypath\java\Users/Kashif/Desktop/Muhammad Kashif/Documents/NetBeansProjects/Torch/Reports/report11.jrxml