Pessoal,
Eu estou fazendo relatórios usando JasperReports e a ferramenta iReport para desenhar, consigo gerar os arquivos: .jasper, .jrprint e inclusive o .pdf (que é o resultado final) ele é gerado e os dados estão todos corretos, consigo abrir ele indo até o diretório em que se encontra.
O meu problema está ao tentar mostrar esse relatório através da minha aplicação, quando tento isso, resulta no seguinte erro:
java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.(Unknown Source)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:87)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:64)
at net.sf.jasperreports.view.JRViewer.loadReport(JRViewer.java:1287)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:201)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:172)
at net.sf.jasperreports.view.JasperViewer.(JasperViewer.java:140)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:397)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:328)
at br.com.cincodhortflor.relatorios.TesteJasper.metodo(TesteJasper.java:51)
at br.com.cincodhortflor.telas.TelaPrincipal$31.actionPerformed(TelaPrincipal.java:560)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.doReturn(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
NESTED BY :
java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.(Unknown Source)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:87)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:64)
at net.sf.jasperreports.view.JRViewer.loadReport(JRViewer.java:1287)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:201)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:172)
at net.sf.jasperreports.view.JasperViewer.(JasperViewer.java:140)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:397)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:328)
at br.com.cincodhortflor.relatorios.TesteJasper.metodo(TesteJasper.java:51)
at br.com.cincodhortflor.telas.TelaPrincipal$31.actionPerformed(TelaPrincipal.java:560)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.doReturn(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
NESTED BY :
net.sf.jasperreports.engine.JRException: Error loading object from file : D:\arquivos java\eclipse\Caecp\relatoriosjasper\ClientesFisicos.pdf
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:92)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:64)
at net.sf.jasperreports.view.JRViewer.loadReport(JRViewer.java:1287)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:201)
at net.sf.jasperreports.view.JRViewer.(JRViewer.java:172)
at net.sf.jasperreports.view.JasperViewer.(JasperViewer.java:140)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:397)
at net.sf.jasperreports.view.JasperViewer.viewReport(JasperViewer.java:328)
at br.com.cincodhortflor.relatorios.TesteJasper.metodo(TesteJasper.java:51)
at br.com.cincodhortflor.telas.TelaPrincipal$31.actionPerformed(TelaPrincipal.java:560)
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.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.doReturn(Unknown Source)
at javax.swing.plaf.basic.BasicPopupMenuUI$Actions.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
Caused by: java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.(Unknown Source)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:87)
… 44 more
A classe para gerar o relatório é a seguinte:
package br.com.sistema.relatorios;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import br.com.sistema.control.ClienteFisicoControl;
import br.com.sistema.util.PathAplicacao;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.view.JasperViewer;
public class TesteJasper {
public void metodo(){
ClienteFisicoControl control = new ClienteFisicoControl();
ResultSet rs = control.listOrdemCidadeRelatorio();
/* implementação da interface JRDataSource para DataSource ResultSet */
JRResultSetDataSource jrRS = new JRResultSetDataSource( rs );
/* HashMap de parametros utilizados no relatório. Sempre instanciados */
Map<String, String> parameters = new HashMap<String, String>();
/* Preenche o relatório com os dados. Gera o arquivo BibliotecaPessoal.jrprint */
try {
JasperFillManager.fillReportToFile( PathAplicacao.getPath("relatoriosjasper") + "ClientesFisicos.jasper", parameters, jrRS );
/* Exporta para o formato PDF */
JasperExportManager.exportReportToPdfFile( PathAplicacao.getPath("relatoriosjasper") + "ClientesFisicos.jrprint" );
/* Visualiza o relatório em formato PDF */
JasperViewer.viewReport( PathAplicacao.getPath("relatoriosjasper") + "ClientesFisicos.pdf", false );
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
O problema está na linha:
JasperViewer.viewReport( PathAplicacao.getPath(“relatoriosjasper”) + “ClientesFisicos.pdf”, false );
Obs.: estou chamando este método através de um JMenuItem dentro de uma classe JFrame.
Desde já agradeço