Exception when using fillmanager and Netbeans

0

Hi guys, I'm new to jasper world in Java, I'd like to make some reports from a database, I'm following a tutorial but the tutorial was made by 2009 and jasper library by that time was 3.7 so maybe that's the problem i'm facing right now but my problem is with the fillmanager cause I'm passing two parameters with a map but I've got an error and don't know how to solve it so here is the image of the error:

Hope someone can help me.

lforero's picture
Joined: Aug 26 2014 - 7:56pm
Last seen: 6 years 1 month ago

The third parameter is interface JRDataSource. What is ParticipantesDataSource? Show source of this class

sanbez - 6 years 1 month ago

here is the code of the class:

package reportes2;
import java.util.ArrayList;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
 
/** * * @author Leonardo */
 
public class ParticipantesDatasource implements 
JRDataSource{
    private List<Participante>
    listaParticipantes = new ArrayList<Participante>();
    private int indiceParticipanteActual=-1;
    @Override
        public Object getFieldValue (JRField jrfield) throws 
            JRException {
                Object valor= null;
                if("nombre".equals(jrfield.getName())) {
                    valor= listaParticipantes.get(indiceParticipanteActual).getNombre();
                }
                else if("username".equals(jrfield.getName()))
                {
                    valor=listaParticipantes.get(indiceParticipanteActual).getUsername();
                }
                else if("password".equals(jrfield.getName()))
                {
                    valor=listaParticipantes.get(indiceParticipanteActual).getPassword();
                }
                else if("comentarios".equals(jrfield.getName()))
                {
                    valor=listaParticipantes.get(indiceParticipanteActual).getComentarios();
                }
                return valor;
            }
    @Override
        public boolean next() throws
            JRException {
                return ++indiceParticipanteActual < listaParticipantes.size();
                       //To change body of generated methods, choose Tools | Templates.
            }
        public void addParticipante (Participante participante){
            this.listaParticipantes.add(participante);
        }
}
lforero - 6 years 1 month ago

1 Answer:

0

error: argument mismatch; Map<String, String> connot be converted to Map<String, Object>



replace declaration


Map<String,String> parametros = new HashMap<>


to


Map<String, Object> parametros = new HashMap<String,Object>

 

sanbez's picture
870
Joined: Jan 11 2011 - 2:06am
Last seen: 1 week 6 days ago

You were totally right, I've changed String to Object and the error went away.

Another question, I'm using library ver 5.5.1 and with this ver I'm able to use this Line:

JasperReport reporte= (JasperReport) JRLoader.loadObject("report2.jasper");

But if I swith library ver to the last 5.6 then the line is marked as error and the JRLoader marked as deprecated and library is even marked as that too so is there something I don't know about that?

Thanks for your help.

lforero - 6 years 1 month ago

I am use v4.1.2 and haven't time upgrage applications :) You can download java-source jasperreports-5.6.1-project.tar.gz and find it off one's own bat

sanbez - 6 years 1 month ago
Feedback
randomness