0
Netbeans 6.5を使用しています。レポート用にジャスパーレポートを使用しています。 jasperビューアでファイルを保存すると、.html
以外の形式で保存されません。私。 .pdf
または.xls
には保存されません。jantperviewerの.html以外の形式でレポートを保存する
代わりに、それは例外をスロー:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/lowagie/text/pdf/FontMapper
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:121)
at cbs.ui.ReportUI.GenerateReport(ReportUI.java:220)
at cbs.ui.ReportUI.btnGenerateBillActionPerformed(ReportUI.java:150)
at cbs.ui.ReportUI.access$100(ReportUI.java:37)
at cbs.ui.ReportUI$2.actionPerformed(ReportUI.java:84)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
理由かもしれませんか?
マイレポート作成ファイル:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ReportUI.java
*
* Created on Jul 15, 2009, 12:02:13 AM
*/
package cbs.ui;
import java.sql.SQLException;
import java.util.Vector;
import controller.PopulateData;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JRViewer;
import net.sf.jasperreports.view.JasperViewer;
/**
*
* @author Mohanish Timble
*/
public class ReportUI extends javax.swing.JInternalFrame {
public int SelectedContId;
/** Creates new form ReportUI */
public ReportUI() {
initComponents();
PopulateContractorCombo();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
cmbContractor = new javax.swing.JComboBox();
btnGenerateBill = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Bill Generation Form");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Select Contractor Name"));
jLabel1.setText("Contractor Name:");
cmbContractor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-------Select----------" }));
cmbContractor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbContractorActionPerformed(evt);
}
});
btnGenerateBill.setText("Generate Bill");
btnGenerateBill.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGenerateBillActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnGenerateBill, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnCancel))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(cmbContractor, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(151, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(cmbContractor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnGenerateBill))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(175, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(72, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
PopulateData populateData = new PopulateData();
private void btnGenerateBillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateBillActionPerformed
try {
// TODO add your handling code here:
GenerateReport();
} catch (ClassNotFoundException ex) {
Logger.getLogger(ReportUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (JRException ex) {
Logger.getLogger(ReportUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(ReportUI.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_btnGenerateBillActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
cmbContractor.setSelectedIndex(0);
}//GEN-LAST:event_btnCancelActionPerformed
private void cmbContractorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbContractorActionPerformed
// TODO add your handling code here:
String ContName=null;
ContName=cmbContractor.getModel().getSelectedItem().toString();
SelectedContId=populateData.getContIdCorrespondingToContName(ContName);
}//GEN-LAST:event_cmbContractorActionPerformed
public void PopulateContractorCombo()
{
Vector<String> contractor=(Vector<String>)populateData.getContractorList();
//cmbCustomer.removeAllItems();
for(int i=0;i < contractor.size();i++){
cmbContractor.addItem((String)contractor.get(i));
}
}
public void GenerateReport() throws ClassNotFoundException, JRException, SQLException {
String reportSource = "./report/templates/Contractor_Bill.jrxml";
String reportDest = "./report/results/Contractor_Bill";
java.sql.Connection conn = null;
//String reportSource = "./report/templates/HelloReportWorld.jrxml";
//String reportDest = "./report/results/HelloReportWorld.html";
Map<String, Object> params = new HashMap<String, Object>();
params.put("contractorId",SelectedContId);
params.put("Contractor Name",cmbContractor.getModel().getSelectedItem().toString());
try
{
JasperReport jasperReport = null;
try {
//Class.forName("org.git.mm.mysql.jdbc.ClientDriver");
Class.forName("org.gjt.mm.mysql.Driver");
jasperReport = JasperCompileManager.compileReport(reportSource);
// Make the driver class available.
// Create a connection to pass into the report.
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cbs_new", "root", "mohanish");
// Replace the empty JR datasource parameter with
// the connection parameter named conn.
} catch (JRException ex) {
Logger.getLogger(ReportUI.class.getName()).log(Level.SEVERE, null, ex);
}
JasperPrint jasperPrint =JasperFillManager.fillReport(jasperReport, params,conn);
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest+".html");
//JasperExportManager.exportReportToPdfFile(jasperPrint,reportDest+".pdf");
JasperViewer.viewReport(jasperPrint);
//JDialog jviewer = new JDialog();
//JRViewer aViewer = new JRViewer(jasperPrint);
//jviewer.setTitle("Bill 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);
}
catch (JRException ex)
{
ex.printStackTrace();
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnGenerateBill;
private javax.swing.JComboBox cmbContractor;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration//GEN-END:variables
}