java.lang.NullPointerException - menu para abrir relatório

9 respostas Resolvido
java
Samuel_Ribeiro

Bom dia.
A uns dias atrás postei um erro que estava dando no mesmo objeto, mas pelo fato de ter que fazer umas alterações no tratamento do código apareceu este erro, e com a ajuda de um colega conseguimos descobrir que o erro esta na variável “conexao” do código que segue abaixo. E faz 3 dias que não consigo resolver.

private void menRelCliActionPerformed(java.awt.event.ActionEvent evt) {                                          
                                          
// Gerando um relatório de Clientes

int confirma = JOptionPane.showConfirmDialog(null, "Confirma a impressão do relatório de Cliente?", "Atenção", JOptionPane.YES_NO_OPTION);

if (confirma == JOptionPane.YES_OPTION) {
    // Imprimindo o relatório de Clentes com o framework jaspersoft studio
   try {
            //Possibilita a compilação do jrxml em tempo de execução
            //JasperReport report = JasperCompileManager.compileReport("Os/MyReports/relatorioClientes.jrxml");
            
            //Possibilita adicionar parâmetros no relatório
            Map<String, Object> parameters = new HashMap<>();
            
            //List<String> list = new ArrayList<>();
            //list.add("Teste");
            //JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
            //https://o7planning.org/en/10293/calling-jasper-report-from-java-application
            
            //Escreve o arquivo jarper
            JasperPrint print = JasperFillManager.fillReport("/home/samuel/Documentos/projetoOs/WorkSpace/prjOrdemDeServicos/src/br/com/Os/MyReports/relatorioClientes.jasper", parameters, conexao);
            
            //Exporta o arquivo gerado no formato pdf
            JasperExportManager.exportReportToPdfFile(print,"/home/samuel/Documentos/projetoOs/WorkSpace/prjOrdemDeServicos/src/br/com/Os/MyReports/relatorioClientes.pdf");
       } catch (Exception e) {
       e.printStackTrace();
       //JOptionPane.showInputDialog(null, e);
    }
}

}

Segue o erro:

java.lang.NullPointerException
at com.jaspersoft.studio.debug.TraceGovernor.setup(TraceGovernor.java:107)
at com.jaspersoft.studio.debug.TraceGovernor.initMaps(TraceGovernor.java:114)
at com.jaspersoft.studio.debug.TraceGovernor.beforeReportInit(TraceGovernor.java:158)
at net.sf.jasperreports.engine.fill.JRFillDatasetScriptlet.beforeReportInit(JRFillDatasetScriptlet.java:74)
at net.sf.jasperreports.engine.JRAbstractScriptlet.callBeforeReportInit(JRAbstractScriptlet.java:176)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:229)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:99)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:609)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:387)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:109)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:286)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:759)
at br.com.Os.telas.TelaPrincipal.menRelCliActionPerformed(TelaPrincipal.java:287)
at br.com.Os.telas.TelaPrincipal.access$400(TelaPrincipal.java:27)
at br.com.Os.telas.TelaPrincipal$5.actionPerformed(TelaPrincipal.java:141)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:842)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:886)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2237)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2295)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
at java.awt.Container.dispatchEventImpl(Container.java:2281)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

9 Respostas

R

O que você está passando na variável conexao?
O erro é porque ele está recebendo null nessa variável e dentro do seu código que você nos mostrou ela não está recebendo nada e nem está declarada, então acho que isso pode estar sendo feito em outra parte do código, poste ele ai.

Samuel_Ribeiro

Bom dia
Obrigado pelo retorno, segue o código do modulo conexão

import java.sql.*;

/**
*

  • @author samuel
    */
    public class ModuloConexao {

    // Metodo responsavel por estabelecer conxão com o banco de dados
    
    public static Connection conector() {
    
    java.sql.Connection conexao = null;
    
    // A linha abaixo chama o Driver de conexão
     String driver = "com.mysql.jdbc.Driver";
     // Armazenando informações referente ao banco
     String url = "jdbc:mysql://localhost:3306/dbordemdeservicos";
     String user = "root";
     String password = "";
     
     // Estabelecendo a conexão com o banco de dados
     
     try {
       Class.forName(driver);
       conexao = DriverManager.getConnection(url, user, password);
       return conexao;
                 
     }
         catch (Exception e) {
         // A linha abixo serve de apoio para exclarecer o erro
          System.out.println(e);
       return null;  
     }
    

    }

}

Samuel_Ribeiro

Veja o código completo da classe

package br.com.Os.telas;
import br.com.Os.dal.ModuloConexao;

import java.text.DateFormat;

import java.util.Date;

import javax.swing.JOptionPane;

import java.sql.*;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import net.sf.jasperreports.engine.JasperExportManager;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

/**
*

  • @author Samuel
    */
    public class TelaPrincipal extends javax.swing.JFrame {

    Connection conexao = null;

    /**

    • Creates new form TelaPrincipal
      */
      public TelaPrincipal() {
      initComponents();
      conexao = ModuloConexao.conector();
      }

    /**

    • 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)
      
      // 
      
      private void initComponents() {
      
      jLabel2 = new javax.swing.JLabel();
      
      Desktop = new javax.swing.JDesktopPane();
      
      lblUsuario = new javax.swing.JLabel();
      
      lblData = new javax.swing.JLabel();
      
      jLabel3 = new javax.swing.JLabel();
      
      jLabel1 = new javax.swing.JLabel();
      
      Menu = new javax.swing.JMenuBar();
      
      MenCad = new javax.swing.JMenu();
      
      MenCadCli = new javax.swing.JMenuItem();
      
      MenCadOs = new javax.swing.JMenuItem();
      
      MenCadUsu = new javax.swing.JMenuItem();
      
      MenRel = new javax.swing.JMenu();
      
      menRelCli = new javax.swing.JMenuItem();
      
      MenRelSer = new javax.swing.JMenuItem();
      
      MenAju = new javax.swing.JMenu();
      
      MenAjuSob = new javax.swing.JMenuItem();
      
      MenOpc = new javax.swing.JMenu();
      
      MenOpcSai = new javax.swing.JMenuItem();
      

      jLabel2.setText(“jLabel2”);

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      
      setTitle(Sistema para controle de Ordem de Serviços.);
      
      setResizable(false);
      
      addWindowListener(new java.awt.event.WindowAdapter() {
      
      public void windowActivated(java.awt.event.WindowEvent evt) {
      
      formWindowActivated(evt);
      
      }
      
      });
      

      Desktop.setPreferredSize(new java.awt.Dimension(730, 450));

      javax.swing.GroupLayout DesktopLayout = new javax.swing.GroupLayout(Desktop);
      
      Desktop.setLayout(DesktopLayout);
      
      DesktopLayout.setHorizontalGroup(
      
      DesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGap(0, 732, Short.MAX_VALUE)
      
      );
      
      DesktopLayout.setVerticalGroup(
      
      DesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGap(0, 450, Short.MAX_VALUE)
      
      );
      

      lblUsuario.setFont(new java.awt.Font(“Tahoma”, 1, 18)); // NOI18N
      lblUsuario.setText(“Usuário”);

      lblData.setFont(new java.awt.Font(Tahoma, 1, 24)); // NOI18N
      
      lblData.setForeground(new java.awt.Color(0, 0, 153));
      
      lblData.setText(Data);
      

      jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/Os/icones/IT_Support_icon-300x300.png"))); // NOI18N

      jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/Os/icones/at.jpg"))); // NOI18N

      MenCad.setText(“Cadastro”);

      MenCadCli.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
      
      MenCadCli.setText(Clientes);
      
      MenCadCli.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      MenCadCliActionPerformed(evt);
      
      }
      
      });
      
      MenCad.add(MenCadCli);
      
      MenCadOs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK));
      
      MenCadOs.setText(Ordem de Serviços);
      
      MenCadOs.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      MenCadOsActionPerformed(evt);
      
      }
      
      });
      
      MenCad.add(MenCadOs);
      
      MenCadUsu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.ALT_MASK));
      
      MenCadUsu.setText(Usuários);
      
      MenCadUsu.setEnabled(false);
      
      MenCadUsu.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      MenCadUsuActionPerformed(evt);
      
      }
      
      });
      
      MenCad.add(MenCadUsu);
      

      Menu.add(MenCad);

      MenRel.setText(“Relatórios”);
      MenRel.setEnabled(false);

      menRelCli.setText(Cliente);
      
      menRelCli.setToolTipText("");
      
      menRelCli.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      menRelCliActionPerformed(evt);
      
      }
      
      });
      
      MenRel.add(menRelCli);
      
      MenRelSer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
      
      MenRelSer.setText(Serviços);
      
      MenRel.add(MenRelSer);
      

      Menu.add(MenRel);

      MenAju.setText(“Ajuda”);

      MenAjuSob.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
      
      MenAjuSob.setText(Sobre);
      
      MenAjuSob.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      MenAjuSobActionPerformed(evt);
      
      }
      
      });
      
      MenAju.add(MenAjuSob);
      

      Menu.add(MenAju);

      MenOpc.setText(“Opções”);

      MenOpcSai.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
      
      MenOpcSai.setText(Sair);
      
      MenOpcSai.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      MenOpcSaiActionPerformed(evt);
      
      }
      
      });
      
      MenOpc.add(MenOpcSai);
      

      Menu.add(MenOpc);

      setJMenuBar(Menu);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      
      getContentPane().setLayout(layout);
      
      layout.setHorizontalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addComponent(Desktop, javax.swing.GroupLayout.PREFERRED_SIZE, 732, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(layout.createSequentialGroup()
      
      .addGap(10, 10, 10)
      
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(lblData)
      
      .addComponent(lblUsuario)
      
      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addContainerGap(14, Short.MAX_VALUE))
      
      .addGroup(layout.createSequentialGroup()
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addContainerGap())))
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(Desktop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGroup(layout.createSequentialGroup()
      
      .addComponent(lblUsuario)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(lblData)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)))
      
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      
      );
      
      setSize(new java.awt.Dimension(1037, 539));
      
      setLocationRelativeTo(null);
      
      }//
      
    private void formWindowActivated(java.awt.event.WindowEvent evt) {
    
    // A linha abaixo substitui a label lbldata pela data atual
    
    // do sistema ao iniciar o form
    
    Date data = new Date();
    
    DateFormat formatador = DateFormat.getDateInstance(DateFormat.DEFAULT);
    
    lblData.setText(formatador.format(data));
    

    }

    private void MenOpcSaiActionPerformed(java.awt.event.ActionEvent evt) {
    
    // Exibe uma caixa de dialogo
    
    int sair = JOptionPane.showConfirmDialog(null, Você tem certeza que deseja sair do sistema!!, Atenção!!, JOptionPane.YES_NO_OPTION);
    
    if (sair == JOptionPane.YES_OPTION) {
    
    System.exit(0);
    
    }
    

    }

    private void MenAjuSobActionPerformed(java.awt.event.ActionEvent evt) {
    
    // Chamando a tela Sbre
    
    TelaSobre sobre = new TelaSobre();
    
    sobre.setVisible(true);
    
    }
    
    private void MenCadUsuActionPerformed(java.awt.event.ActionEvent evt) {
    
    // As linhas abaixo vão abrir o form Tela Usuário dentro do DesktopPane
    
    TelaUsuario usuario = new TelaUsuario();
    
    usuario.setVisible(true);
    
    Desktop.add(usuario);
    
    }
    
    private void MenCadCliActionPerformed(java.awt.event.ActionEvent evt) {
    
    // Chamando a TelaCliente:
    
    TelaCliente cliente = new TelaCliente();
    
    cliente.setVisible(true);
    
    Desktop.add(cliente);
    
    }
    
    private void MenCadOsActionPerformed(java.awt.event.ActionEvent evt) {
    
    // Chamando a Tela de Abertura de Ordem de Serviços
    
    TelaOs os = new TelaOs();
    
    os.setVisible(true);
    
    Desktop.add(os);
    
    }
    

    private void menRelCliActionPerformed(java.awt.event.ActionEvent evt) {

    // Gerando um relatório de Clientes

    int confirma = JOptionPane.showConfirmDialog(null, “Confirma a impressão do relatório de Cliente?”, “Atenção”, JOptionPane.YES_NO_OPTION);

    if (confirma == JOptionPane.YES_OPTION) {
    
    // Imprimindo o relatório de Clentes com o framework jaspersoft studio
    
    try {
    
    //Possibilita a compilação do jrxml em tempo de execução
    
    //JasperReport report = JasperCompileManager.compileReport(“Os/MyReports/relatorioClientes.jrxml”);
    
    //Possibilita adicionar parâmetros no relatório
             Map<String, Object> parameters = new HashMap<>();
             
             //List<String> list = new ArrayList<>();
             //list.add("Teste");
             //JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
             //https://o7planning.org/en/10293/calling-jasper-report-from-java-application
             
             //Escreve o arquivo jarper
             JasperPrint print = JasperFillManager.fillReport("/home/samuel/Documentos/projetoOs/WorkSpace/prjOrdemDeServicos/src/br/com/Os/MyReports/relatorioClientes.jasper", parameters, conexao);
             
             //Exporta o arquivo gerado no formato pdf
             JasperExportManager.exportReportToPdfFile(print,"/home/samuel/Documentos/projetoOs/WorkSpace/prjOrdemDeServicos/src/br/com/Os/MyReports/relatorioClientes.pdf");
        } catch (Exception e) {
        e.printStackTrace();
        //JOptionPane.showInputDialog(null, e);
     }
    

    }

    }

    /**

    • @param args the command line arguments
      /
      public static void main(String args[]) {
      /
      Set the Nimbus look and feel /
      //
      /
      If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
      • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if (“Nimbus”.equals(info.getName())) {
        javax.swing.UIManager.setLookAndFeel(info.getClassName());
        break;
        }
        }
        } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //
    /* Create and display the form */
    
    java.awt.EventQueue.invokeLater(() -> {
    
    new TelaPrincipal().setVisible(true);
    
    });
    
    }
    
    // Variables declaration - do not modify
    
    private javax.swing.JDesktopPane Desktop;
    
    private javax.swing.JMenu MenAju;
    
    private javax.swing.JMenuItem MenAjuSob;
    
    private javax.swing.JMenu MenCad;
    
    private javax.swing.JMenuItem MenCadCli;
    
    private javax.swing.JMenuItem MenCadOs;
    
    public static javax.swing.JMenuItem MenCadUsu;
    
    private javax.swing.JMenu MenOpc;
    
    private javax.swing.JMenuItem MenOpcSai;
    
    public static javax.swing.JMenu MenRel;
    
    private javax.swing.JMenuItem MenRelSer;
    
    private javax.swing.JMenuBar Menu;
    
    private javax.swing.JLabel jLabel1;
    
    private javax.swing.JLabel jLabel2;
    
    private javax.swing.JLabel jLabel3;
    
    private javax.swing.JLabel lblData;
    
    public static javax.swing.JLabel lblUsuario;
    
    private javax.swing.JMenuItem menRelCli;
    
    // End of variables declaration
    
    }
    
R

Certo, se você está recebendo a conexao nessa classe e partindo do principio que o problema seja nela mesmo, a sua conexao está retornando null e o seu

Que está exibindo a mensagem de erro.

A conexao funciona normalmente em outras classes?

Samuel_Ribeiro

Sim funciona em toda as outras classes, só ao abrir relatórios que retorna este erro

Samuel_Ribeiro

Veja o erro que retornou

java.lang.NullPointerException CONSTRUÍDO COM SUCESSO (tempo total: 28 segundos)

Uma pergunta:
Pode ser pelo fato de eu ter criado um pacote “br.com.Os.MyReports” e salvar os relatórios dentro do projeto, e na compilação do relatório no JasperSoft studio ter copiado a url do relatório e adicionado no código?

R

Se você colocou os .jasper que você criou dentro do seu projeto em “br.com.Os.MyReports”, o caminho que você deve passar é esse. /br/com/OS/MyReports.
Caso exista o relatório também no caminho que você passou, não deveria estar retornando erro.

Ainda estou em dúvidas quanto a essa conexao ser realmente o problema, por conta de ela ter funcionado em outras classes, ela não deveria estar retornando null.
Debuga o código e coloca um breakpoint aqui:

JasperPrint print = JasperFillManager.fillReport("/home/samuel/Documentos/projetoOs/WorkSpace/prjOrdemDeServicos/src/br/com/Os/MyReports/relatorioClientes.jasper", parameters, conexao);

E veja se ela está recebendo mesmo null.

Samuel_Ribeiro

Rodrigo
Retornou a mesma mensagem

“java.lang.NullPointerException” este ta complicado

Samuel_Ribeiro
Solucao aceita

Boa tarde Rodrigo
Conseguimos gerar o relatório
O problema era as bibliotecas, estas atuais não estão funcionando corretamente, veja as que colocamos
commons-beanutils-1-9-3.jar
commons-collection-3.2.2.jar
commons-logging-1.2.jar
groov-all.2.4.5.jar
jasperreports-6.5.1.jar
commons-digester-2.1.jar
itext-pdfa-5.5.12.jar
itext-pdf-5.5.12.jar
itext-2.1.7.jar

Agradeço muito ao fórum pelo empenho em me ajudar e ao meu Grande colega Wellington Rodrigues grande força.

Criado 1 de fevereiro de 2018
Ultima resposta 1 de fev. de 2018
Respostas 9
Participantes 2