Java - Proble con FileNotFoundExeption

 
Vista:

Proble con FileNotFoundExeption

Publicado por Luis (83 intervenciones) el 05/01/2010 04:27:24
Este es codigo de una vista que cuya utilidad es pasarle un parametro de prueba a un Reporte jasperReport.

public class Reporte extends javax.swing.JFrame
{
private String id;
private ReporteAgenda jasper;
/** Creates new form Reporte */
public Reporte()
{
initComponents();
jasper = new ReporteAgenda();
}

/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

cmdStart = new javax.swing.JButton();
txtID = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

cmdStart.setText("Reporte");
cmdStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdStartActionPerformed(evt);
}
});

jLabel1.setText("ID:");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txtID, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmdStart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(100, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(26, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdStart)
.addContainerGap())
);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-324)/2, (screenSize.height-162)/2, 324, 162);
}// </editor-fold>

private void cmdStartActionPerformed(java.awt.event.ActionEvent evt)
{
id = txtID.getText();
//ReporteAgenda jasper = new ReporteAgenda(id);
jasper.runReporte(id);
}

/**
* @param args the command line arguments
*/
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new Reporte().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton cmdStart;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField txtID;
// End of variables declaration

}

Este es el codigo que utilizo para pasarle el parametro a una consulta en el reporte y mostrar el reporte. Este codigo lo que hace es hacer una conex a la base de datos e intenta lanzar el reporte.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.*;

/**
*
* @author WinDoctor
*/
public class ReporteAgenda
{
private Connection conn;
private final String login = "root"; //usuario de acceso a MySQL
private final String password = ""; //contraseña de usuario
private String url = "jdbc:mysql://localhost/addressbook";
private String id_contact;
public ReporteAgenda()
{
try
{
Class.forName("com.mysql.jdbc.Driver"); //se carga el driver
conn = DriverManager.getConnection(url,login,password);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}

}

public void runReporte(String id_contact)
{
//this.id_contact="";
//this.id_contact = id;

try
{
String master = System.getProperty("user.dir") +
"/reportes/contactos.jasper";

System.out.println("master" + master);
if (master == null)
{
System.out.println("No encuentro el archivo del reporte maestro.");
System.exit(2);
}

JasperReport masterReport = null;
try
{
masterReport = (JasperReport) JRLoader.loadObject(master);
}
catch (JRException e)
{
System.out.println("Error cargando el reporte maestro: " + e.getMessage());
System.exit(3);
}

//este es el parámetro, se pueden agregar más parámetros
//basta con poner mas parametro.put
Map parametro = new HashMap();
parametro.put("id",id_contact);

//Reporte diseñado y compilado con iReport
JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport,parametro,conn);

//Se lanza el Viewer de Jasper, no termina aplicación al salir
JasperViewer jviewer = new JasperViewer(jasperPrint,false);
jviewer.setTitle("MUNDO BYTE");
jviewer.setVisible(true);
}

catch (Exception j)
{
System.out.println("Mensaje de Error:"+j.getMessage());
}

}

public void cerrar()
{
try
{
conn.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}

}

El problema es que si yo ejecuto este reporte con el ireport sin parametro lo muestra en el visor de netbeans. El problema viene cuando ejecuto la vista y le paso el parametro y me da el siguiente error: Error cargando el reporte maestro: java.io.FileNotFoundException: C:\Users\Luis\Desktop\Ejemplo_Reportes\reportes\contactos.jasper

Entiendo que esa excepcion significa o que no encuentra el archivo o que el mismo no funciona.

Pero si no funciona no lo mostraria en el visor de netbeans creo yo.

Lo otro que se me ocurre es que sean las librerias. yo le añadi al proyecto las librerias que trae ireport. Asi que no se me ocurre nada aparte de que las librerias tengan algo malo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder