Estou com a seguinte classe q mostra um relatorio criado no ireport 3.0 !
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package classes;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.*;
/**
*
* @author Administrador
*/
public class Relatorios {
private static Connection getConnection() throws
ClassNotFoundException, SQLException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://suporte02/sasi";
String user = "root";
String password = "xxxxxx";
Class.forName(driver);
Connection con = DriverManager.getConnection(url, user, password);
return con;
}
public static void main(String[] args) throws JRException, Exception {
new Relatorios().geraRelatorio();
}
private void geraRelatorio() throws JRException {
//supondo que o teu ficheiro teste.jasper esteja dentro da tiua aplicação
URL arquivo = getClass().getResource("D:/Programas java/sasi/relMovimentacao/relMovimentacoes.jasper");
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(arquivo);
//aqui, como não vais passar parâmetros para dentro do relatório, e porque estou a assumir que não tenhas ligação com base de dados, os dois ultimos parametros são nulos
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null);
//isto mostra.te o viewer, penso que é a melhor maneira, pois assim a pessoa escolhe o formato em que quer gravar, e o sitio onde gravar
JasperViewer jrviewer = new JasperViewer(jasperPrint, false);
jrviewer.setVisible(true);
}
}
E o erro é esse:
Exception in thread “main” java.lang.NullPointerException
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:139)
at classes.Relatorios.geraRelatorio(Relatorios.java:42)
at classes.Relatorios.main(Relatorios.java:36)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)
Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:96)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:147)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
at telas.RelatorioMovimentacao.jButton3ActionPerformed(RelatorioMovimentacao.java:255)
at telas.RelatorioMovimentacao.access$200(RelatorioMovimentacao.java:23)
at telas.RelatorioMovimentacao$4.actionPerformed(RelatorioMovimentacao.java:105)
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:6288)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6053)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
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:2478)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
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.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
… 43 more
Acabei de descobrir orro pelo dos ! Aquele esquema: java - jar nomeaplicacao.jar
Ele nao ta achando a figura q tem no relatorio. No caso, O logo da empresa q eu coloquei !
Olha o erro aqui:
01/09/2011 16:32:16 telas.RelatorioMovimentacao jButton3ActionPerformed
GRAVE: null net.sf.jasperreports.engine.JRException: Byte data not found at location : C:\Us
ers\Administrador\Desktop\relMovimentacao\logo_SI_transparente.png
at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoa
der.java:482)
at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRender
er.java:177)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImag
e.java:924)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.jav
a:871)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFi
llElementContainer.java:275)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
426)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillTitle(JRVertica
lFiller.java:311)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRV
erticalFiller.java:247)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
alFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
879)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
782)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63
)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
nager.java:402)
at telas.RelatorioMovimentacao.jButton3ActionPerformed(RelatorioMoviment
acao.java:257)
at telas.RelatorioMovimentacao.access$200(RelatorioMovimentacao.java:22)
at telas.RelatorioMovimentacao$4.actionPerformed(RelatorioMovimentacao.j
ava:107)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)