0

I created the following report from an Access database:

enter image description here

This only use two parameters: $P{Image} (for set my resource icon) and $P{Cedula} (for WHERE clause). In Jaspersoft Studio works perfect... I already knew from the beginning that the biggest challenge would be to call this report from java.

I read some questions from this site and here. In VB.NET currently I do something similar to the last page (data source from a class) with reportViewer, so I made the following class:

package DataBeans;

public class Paciente {
private String nombre,apellido,cedula;
private String fecha_nacimiento,sexo,tipo_sangre;
private String direccion,telefono;

public void setNombre(String v){nombre=v;}
public void setApellido(String v){apellido=v;}
public void setCedula(String v){cedula=v;}
public void setFechaNacimiento(String v){fecha_nacimiento=v;}
public void setSexo(String v){sexo=v;}
public void setTipoSangre(String v){tipo_sangre=v;}
public void setDireccion(String v){direccion=v;}
public void setTelefono(String v){telefono=v;}
public String getNombre(){return nombre;}
public String getApellido(){return apellido;}
public String getCedula(){return cedula;}
public String getFechaNacimiento(){return fecha_nacimiento;}
public String getSexo(){return sexo;}
public String getTipoSangre(){return tipo_sangre;}
public String getDireccion(){return direccion;}
public String getTelefono(){return telefono;}
}

And the class "DataBeans", like the site:

package DataBeans;

import Clases.Administrador;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class DataBeans {
    public ArrayList<Paciente> getPacientes(String[] values) throws ClassNotFoundException, SQLException{
        Administrador admin = new Administrador();
        ArrayList<Paciente> ListaPacientes = new ArrayList<>();
        ResultSet rs = admin.SelectParametrizado(values, "SELECT * FROM Pacientes WHERE Cedula=?");
        while(rs.next()){
            ListaPacientes.add(producirPaciente(rs.getString("Nombre"), rs.getString("Apellido"), rs.getString("Cedula")
            ,rs.getString("Fecha_Nacimiento"),rs.getString("Sexo"),rs.getString("Tipo_Sangre")
            ,rs.getString("Direccion"),rs.getString("Telefono")));
        }
        return ListaPacientes;
    }

    public Paciente producirPaciente(String n, String a, String c, String fn, String s, String ts, String d, String t){
        Paciente pac = new Paciente();
        pac.setNombre(n);
        pac.setApellido(a);
        pac.setCedula(c);
        pac.setFechaNacimiento(fn);
        pac.setSexo(s);
        pac.setTipoSangre(ts);
        pac.setDireccion(d);
        pac.setTelefono(t);
        return pac;
    }
    }

I think my intentions are clearly reflected what I try to achieve with the code of both classes. The Function "SelectParametrizado" (parameterizedSelect) returns me a ResultSet that I use to fill data to each element of arrayList (ListaPacientes). I want to use that ArrayList like a DataSource for my report.

I think actually this question will be double .... for the following reason:

With this code

private JasperPrint impresion;
private JasperReport reporte;
private JRViewer reportViewer;
private JRBeanCollectionDataSource data;
private HashMap<String,Object> parametros;
private String[] values;
private DataBeans beans;

values = new String[1];
values[0] = "3-333-3333";
beans = new DataBeans();
data = new JRBeanCollectionDataSource(beans.getPacientes(values));
    parametros = new HashMap<>();
    reporte = (JasperReport) JRLoader.loadObject(new File("Reportes/PerfilPaciente.jasper"));
    impresion = JasperFillManager.fillReport(reporte,parametros,data);
    reportViewer = new JRViewer(impresion);

I get the following error...

enter image description here

Probably, you will think something like "yes, because you didnt set the Image parameter", but that is not working too...

 data = new JRBeanCollectionDataSource(beans.getPacientes(values));
    parametros = new HashMap<>();
   **parametros.put("Imagen", ClassLoader.getSystemResource("perfil-azul.png").getPath());**
    reporte = (JasperReport) JRLoader.loadObject(new File("Reportes/PerfilPaciente.jasper"));
    impresion = JasperFillManager.fillReport(reporte, parametros,data);
    reportViewer = new JRViewer(impresion);

I get "null-pointerException"..

enter image description here

How I can achieve: Loading a dataset from an arraylist and set one Image parameter for my report...?

If you know another way, feel free to comment it here... Be assured that It will be of tremendous help.

TwoDent
  • 405
  • 7
  • 26
  • This NPE is coming from BuscaPaciente, could you post this class here? At least the constructor – Bruno Nov 01 '16 at 01:34
  • @TwoDent It is a bad practice to post the stacktrace as an image – Alex K Nov 01 '16 at 07:37
  • Possible duplicate of [JRBeanCollectionDataSource: How to show data from the java.util.List from JavaBean?](http://stackoverflow.com/questions/12209300/jrbeancollectiondatasource-how-to-show-data-from-the-java-util-list-from-javabe) – Alex K Nov 01 '16 at 07:44

0 Answers0