Venho mais uma vez recorrer ao conhecimento geral do grupo. Tenho um relatório criado no ireport, quando faço a chamada para a visualização do mesmo ele gera um exceção :
Exception in thread "main" java.lang.NullPointerException
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:141)
at chamaireport.Relatorio.geraRelatorio(Relatorio.java:40)
at chamaireport.Relatorio.main(Relatorio.java:32)
Java Result: 1
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
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.JasperCompileManager.getCompiler(JasperCompileManager.java:511)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:148)
at chamaireport.JFTeste.VisualizarRelatorio(JFTeste.java:107)
at chamaireport.JFTeste.jButton1ActionPerformed(JFTeste.java:80)
at chamaireport.JFTeste.access$000(JFTeste.java:27)
at chamaireport.JFTeste$1.actionPerformed(JFTeste.java:55)
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:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 36 more
segue o código:
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.*;//para objeto JasperReport
import net.sf.jasperreports.view.*;//para objeto JasperViewer
public class JFTeste extends javax.swing.JFrame {
private Map parametros = new HashMap();
private JasperReport relatorio;
private static final String layout = "c:\SisTerm\src\Relatorios\LeituraTermometria.jrxml";
//URL arquivo = getClass().getResource("c:\SisTerm\src\Relatorios\LeituraTermometria.jrxml");
/** Creates new form JFTeste */
public JFTeste() {
initComponents();
}
/** 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">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
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(22, 22, 22)
.addComponent(jButton1)
.addContainerGap(305, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jButton1)
.addContainerGap(257, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
VisualizarRelatorio();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JFTeste().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
private void exibeErro(String msg, Exception e, boolean fatal) {
JOptionPane.showMessageDialog(null, msg + "\n" + e.getMessage(),"Erro Fatal", JOptionPane.ERROR_MESSAGE);
if (fatal)
System.exit(1);
}
public void VisualizarRelatorio(){
try {
parametros.put("ParamCodiCabe", "16");
relatorio = JasperCompileManager.compileReport(layout);
JasperPrint impressao = JasperFillManager.fillReport(relatorio, parametros);
JasperViewer viewer = new JasperViewer(impressao, false);
viewer.show();
}catch (JRException ex) {
exibeErro("Não foi possível visualizar o relatório.", ex, false);
}catch (Exception e){
exibeErro("Impossível iniciar a aplicação:", e, true);
}
}
}