TransWikia.com

error al mostrar un jasperreport pdf java.io.FileNotFoundException

Stack Overflow en español Asked by kevvelas on February 1, 2021

Hola a todos(as) tengo el siguiente problema:

Al momento de querer mostrar mi jasperreport el “PDF”, me sale el siguiente error java.io.FileNotFoundExceptioncuando coloco la ruta String path = "prueba.jasper"; o cuando lo coloco completo String path = "/src/reporte/prueba.jasper"; aquí debajo les muestro mi código.

Esto es mi código del frame frm_reportearticulos

package Vistas;

import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

public class frm_reportearticulos extends javax.swing.JFrame {
/**
 * Creates new form frm_reportearticulos
 */
public frm_reportearticulos() {
    initComponents();
    setLocationRelativeTo(null);
}
   private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    Connection miconexion = conexion.GetConnection();
    String path = "/src/reporte/prueba.jasper";
    JasperReport jr = null;
    try {
        jr= (JasperReport) JRLoader.loadObjectFromLocation(path);
        JasperPrint jp =JasperFillManager.fillReport(jr,null, miconexion);
        JasperViewer jv = new JasperViewer(jp);
        jv.setVisible(true);
        jv.setTitle(path);

        miconexion.close();
    } catch (Exception e) {
        Logger.getLogger(frm_reportearticulos.class.getName()).log(Level.SEVERE, null,e);
    }

    //empeze a intentar con este codigo primero pero me sale el mismo error java.io.FileNotFoundException
    /*
    Connection miconexion = conexion.GetConnection();

    try {

        String reporte="prueba.jrxml";
        JasperPrint informe =JasperFillManager.fillReport(reporte,null,miconexion);
        JasperViewer ventanavisor=new JasperViewer(informe,false);
        ventanavisor.setTitle("Reporte pizza");
        ventanavisor.setVisible(true);
    } catch (Exception e) {
        //e.printStackTrace();
        JOptionPane.showMessageDialog(this, e.getMessage());
        //System.out.println(e.getMessage());
    }
      */// TODO add your handling code here:
}                                        

private void formWindowClosing(java.awt.event.WindowEvent evt) {                                   
      this.setVisible(false);          // TODO add your handling code here:
}                                                
}

Donde dice jr= (JasperReport) JRLoader.loadObject(path); eh intentado cambiarlo por jr= (JasperReport) JRLoader.loadObjectFromFile(path); pero netbeans me marca con rojo loadObjectFromFile diciendo

cannot find symbol
  symbol:   method loadObjectFromFile(String)
  location: class JRLoader
----
(Alt-Enter shows hints)

Mi clase conexion es el siguiente

package Vistas;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;

public class conexion {

 public static Connection GetConnection()
{
    Connection conexion=null;

    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        String servidor = "jdbc:mysql://localhost/ventacallcenter_v1";
        String usuarioDB="root";
        String passwordDB="";
        conexion= DriverManager.getConnection(servidor,usuarioDB,passwordDB);
    }
    catch(ClassNotFoundException ex)
    {
        JOptionPane.showMessageDialog(null, ex, "Error1 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
        conexion=null;
    }
    catch(SQLException ex)
    {
        JOptionPane.showMessageDialog(null, ex, "Error2 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
        conexion=null;
    }
    catch(Exception ex)
    {
        JOptionPane.showMessageDialog(null, ex, "Error3 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
        conexion=null;
    }
    finally
    {
        return conexion;
    }
}
}

el error que me aparece es el siguiente:

run:
jun 07, 2018 12:55:07 PM Vistas.frm_reportearticulos jButton3ActionPerformed
GRAVE: null
net.sf.jasperreports.engine.JRException: Could not load object from location : srcreporteprueba.jasper
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:273)
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:232)
    at Vistas.frm_reportearticulos.jButton3ActionPerformed(frm_reportearticulos.java:88)
    at Vistas.frm_reportearticulos.access$100(frm_reportearticulos.java:12)
    at Vistas.frm_reportearticulos$2.actionPerformed(frm_reportearticulos.java:53)
    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.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    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:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    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)

One Answer

Creo que requieres escapar los "/". Pero no sé que sistema operativo tengas. Prueba de esta forma:

String path = "\src\reporte\prueba.jasper";

Answered by AlbertoLopez on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP