error showing a jasperreport pdf java.io.FileNotFoundException

0

Hello everyone, I have the following problem:

At the moment of wanting to show my jasperreport the "PDF", I get the following error java.io.FileNotFoundException when I place the path String path = "prueba.jasper"; or when I put full String path = "/src/reporte/prueba.jasper"; here below I show them my code.

This is my% code 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:
}                                                
}

Where it says jr= (JasperReport) JRLoader.loadObject(path); eh tried to change it to jr= (JasperReport) JRLoader.loadObjectFromFile(path); but netbeans marks me with red loadObjectFromFile saying

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

My class conexion is next

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;
    }
}
}

The error that appears to me is the following:

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 : \src\reporte\prueba.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)
    
asked by kevvelas 04.06.2018 в 19:56
source

1 answer

-1

I think you need to escape the "/". But I do not know what operating system you have. Test this way:

String path = "\src\reporte\prueba.jasper";
    
answered by 04.06.2018 в 20:08