Error generating Ireports report (Jasper) in Maven project

Asked

Viewed 26 times

0

I am working with a Maven project and managed a print using Ireports, but when making the call it is returned java.lang.NullPointerException when trying to detail where was the error I noticed that occurs in this line Inputstream report:

getClass().getResourceAsStream("/impresso/ImpressoContaConsumo.jasper");

I thought it could be something with the file, but when trying to use the same report in a project that is not Maven it opens without problems and when trying to run a simple report without parameters it presents the same problem.

Follow the code below.

Impressos.java

    try {

    InputStream relatorio = getClass().getResourceAsStream("/impresso/ImpressoContaConsumo.jasper");

    List<Relatorio> Conta = getListaConta(dataEmissao, mesReferencia, vencimento, totalPagar, nomePredio, endereco,
            numero, bairro, complemento, cidade, uf, cep, dataLeitura, leituraInicial, leituraFinal,
            volumeMC, volumeKG, dataFaturamento, descricaoFaturamento, totalFaturamento, fatorConversao,
            valorUnitario, volumeMCFC, volumeKGFC, diasConsumo);


    
    JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(Conta);

    Map<String, Object> parametros = new HashMap<String, Object>();

    JasperPrint impressao = null;

    impressao = JasperFillManager.fillReport(relatorio, parametros, ds);
    JasperViewer viewer = new JasperViewer(impressao, false);
    viewer.setVisible(true);

} catch (JRException e) {

    JOptionPane.showMessageDialog(null, e.getMessage());
    e.printStackTrace();

}

Error:

>Java.lang.NullPointerException
at java.base/java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2872)
at java.base/java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2888)
at java.base/java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3385)
at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:942)
at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:385)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>    (ContextClassLoaderObjectInputStream.java:53)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:200)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:603)
at br.com.agil.condominio.controle.Impressos.RelatorioVenda(Impressos.java:59)
at br.com.agil.condominio.view.FrameLancaConsumo.GeraConta(FrameLancaConsumo.java:403)
at  br.com.agil.condominio.view.FrameLancaConsumo.BtConsUnidade1ActionPerformed(FrameLancaConsumo.java:221)
at br.com.agil.condominio.view.FrameLancaConsumo.access$300(FrameLancaConsumo.java:28)
at br.com.agil.condominio.view.FrameLancaConsumo$5.actionPerformed(FrameLancaConsumo.java:143)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6401)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2764)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Detail of the imported Maven library in the project for use with Jasperreports

    <dependency>
     <groupId>net.sf.jasperreports</groupId>
     <artifactId>jasperreports</artifactId>
     <version>3.7.5</version>
    </dependency>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.