Problem of InputStream in my JasperReport.

0

I have a problem in my java class when I execute the JasperPrint command and the error is in my InputStream. Because I can´t find de solution to solve this problem, I send this question for you. Thanks.

Class 1:

package ITC_Prontuario_Package;

import java.awt.BorderLayout;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Map;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.swing.JRViewer;
/**
 *
 * @author Cezar Apulchro
 */
public class Report_Utils_A01
{
    public static void openReport(
                String titulo,
                InputStream inputStream,
                Map parametros,
                Connection conexao) throws JRException
    {
        JasperPrint print = JasperFillManager.fillReport(
                inputStream, parametros, conexao);
        
        viewReportFrame( titulo, print );
    }
    
    public static void openReport(
                String titulo,
                InputStream inputStream,
                Map parametros,
                JRDataSource dataSource) throws JRException
    {
        JasperPrint print = JasperFillManager.fillReport(
                inputStream, parametros, dataSource);
        
        viewReportFrame( titulo, print );
    }
    
    private static void viewReportFrame( String titulo, JasperPrint print )
    {
        JRViewer viewer = new JRViewer(print);
        
        JFrame frameRelatorio = new JFrame(titulo);
        
        frameRelatorio.add(viewer, BorderLayout.CENTER);
        
        frameRelatorio.setSize(500, 500);
        
        frameRelatorio.setExtendedState(JFrame.MAXIMIZED_BOTH);
        
        frameRelatorio.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        frameRelatorio.setVisible(true);
    }
}
Main class:

package ITC_Prontuario_Package;

import java.io.InputStream;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import ITC_Prontuario_Package.PacientesDAO_A01;
import ITC_Prontuario_Package.Report_Utils_A01;
import ITC_Prontuario_Package.ConectarBanco;
import java.sql.Connection;
/**
 *
 * @author Cezar Apulchro
 */
public class Report_Main_A01
{
    public Connection conexao;
    private static final String inputS = 
        "C:/Program Files (x86)/ITC_Systems/build/classes/ITC_Prontuario_Package/Relatorio_Clientes_A01.jrxml";
    
    public void abreRelatorio() throws JRException
    {
        conexao = new ConectarBanco().getConnection();
        PacientesDAO_A01 pcdao = new PacientesDAO_A01();
        
        InputStream inputStream = this.getClass().getResourceAsStream(
                /*"/Relatorio_Clientes_A01.jasper");*/
                /*"ITC_Prontuario_Package/Relatorio_Clientes_A01.jasper");*/
                "C:/Program Files (x86)/ITC_Systems/build/classes/ITC_Prontuario_Package/Relatorio_Clientes_A01.jasper");
        
        /*config = this.getClass().getResourceAsStream(inputS);*/
        
        Map parametros = new HashMap();
        
        try
        {
            Report_Utils_A01.openReport("Relacao_Clientes_A01", inputStream, parametros, 
                    ConectarBanco.getConnection());
        }
          catch (JRException ex)
            {
                ex.printStackTrace();
            }
    }
    
    public static void main(String[] args) throws JRException
    {
        new Report_Main_A01().abreRelatorio();
        
    }
}
 

StackTrace:

Exception in thread "main" java.lang.NullPointerException
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2653)
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2669)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3146)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:858)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:354)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:56)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:277)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:262)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:415)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:838)
    at ITC_Prontuario_Package.Report_Utils_A01.openReport(Report_Utils_A01.java:30)
    at ITC_Prontuario_Package.Report_Main_A01.abreRelatorio(Report_Main_A01.java:43)
    at ITC_Prontuario_Package.Report_Main_A01.main(Report_Main_A01.java:54)

cezar_apulchro's picture
Joined: Mar 24 2013 - 5:16pm
Last seen: 10 hours 58 min ago

1 Answer:

1

The problem  solved with InputStream  exchange by FileInputStream.

cezar_apulchro's picture
Joined: Mar 24 2013 - 5:16pm
Last seen: 10 hours 58 min ago
Feedback