我要做的是在jasper iReport中创建一个简单的报告,并在Javafx文件中查看它。
当我尝试打开文件时,它会在此行引发错误:
JasperDesign jasperdesign = JRXmlLoader.load("C:\\Users\\chirag\\Documents\\NetBeansProjects\\User_management_application\\src\\reports\\UserLogs.jrxml");
报告路径是从UserLogs.jrxml
文件
我正在尝试加载报告的方法片段:
try {
JasperReport jasperReport;
JasperPrint jasperPrint;
String qry = "SELECT * FROM user_master a inner join user_log_management b on a.User_Master_Id = b.userMaster_User_Master_Id where b.Entry_Date like '" + date1.getValue() + "%'";
JRDesignQuery newQuer = new JRDesignQuery();
newQuer.setText(qry);
JasperDesign jasperdesign = JRXmlLoader.load("C:\\Users\\chirag\\Documents\\NetBeansProjects\\User_management_application\\src\\reports\\UserLogs.jrxml");
jasperdesign.setQuery(newQuer);
jasperReport = JasperCompileManager.compileReport(jasperdesign);
jasperPrint = JasperFillManager.fillReport(jasperReport, null, MySqlConnection.conn());
boolean isLinuxSelected = radiopdf.isSelected();
if (isLinuxSelected) {
JasperExportManager.exportReportToPdfFile(jasperPrint, "reports//UserLogs.pdf");
String pdflocation = "reports//UserLogs.pdf";
try {
if (Desktop.isDesktopSupported()) {
try {
File myFile = new File(pdflocation);
Desktop.getDesktop().open(myFile);
} catch (Exception ex) {
}
}
} catch (Exception ep) {
Alert alerts = new Alert(Alert.AlertType.ERROR);
alerts.setContentText("Sorry no Records to be previewed.");
alerts.show();
}
} else {
JDialog jviewer = new JDialog();
JRViewer aViewer = new JRViewer(jasperPrint);
jviewer.setTitle("Report Preview");
jviewer.setModal(true);
jviewer.getContentPane().add(aViewer);
jviewer.pack();
java.awt.Dimension diadim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
jviewer.setSize(diadim.width, diadim.height);
jviewer.requestFocus();
jviewer.show();
jviewer.setAlwaysOnTop(true);
}
MySqlConnection.closeConnection();
System.gc();
} catch (JRException ex) {
Logger.getLogger(ReportsController.class.getName()).log(Level.SEVERE, null, ex);
}
错误消息:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1765)
... 50 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
at ControllerPack.ReportsController.generate(ReportsController.java:126)
... 60 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
我无法弄清楚错误,请帮助我。
答案 0 :(得分:1)
基本原因是
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
因此,看起来您没有为JasperReports提供所需的依赖项。在JR版本所需的版本中添加commons-digester-*.jar
(可能还有其他缺少的库)。