2

I am working in this aplication in order to generate reports with JRDataSource interface. I think I am doing ok, but obviusly I'm missing something. I am trying to do a GUI where i can introduce 4 parameters, save them by catching an event (button onClick) within a list and another button onClick to print it in a report using JRDataSource. My guess is that is something related to the onClick 2nd event (print report) because until there the aplication runs good.

You can see my code and the exception that NetBeans is throwing here.

English is not my native language, son Im sorry if I did not explain it very well.

Main Class:

package di_t4;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class DI_T4 extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLFichaAlumno.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

Events from FXMLController:

@FXML
    private void guardar(ActionEvent event) {

        //Botón correspondiente al botón guardar
        String dniVal = txtDNI.getText();
        String modVal = cmbModulo.getValue();
        int notaVal = spnNota.getValue();
        double recuperaVal = spnRecuperacio.getValue();

        if (dniVal.isEmpty()) {
            Alert alerta = new Alert(Alert.AlertType.ERROR);
            alerta.setTitle("ALERT DNI FAIL");
            alerta.setContentText("El DNI que ha introducido no es correcto");
            alerta.showAndWait();
            return;
        }
        Nota nota = new Nota(dniVal, modVal, notaVal, recuperaVal);
        tbNotas.getItems().add(nota);
        listaNota.addNota(nota);
//        notaAlmacenada.insertarNota(nota);
        //limpiamos variables
        txtDNI.setText("");
        cmbModulo.setValue("DI");
        spnNota.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 10, 5));
        spnRecuperacio.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 5, 0, 0.5));
    }

    @FXML
    private void generaInforme(ActionEvent event) {
        try {

            JasperReport reporte = (JasperReport) JRLoader.loadObjectFromFile("InformeNotaAlumnos.jasper");
            JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, null, listaNota);

            JasperViewer jviewer = new JasperViewer(jasperPrint);
            jviewer.setVisible(true);
        } catch (JRException jrex) {
            System.out.println(jrex.getCause());
        }
    }

I've tried to put this inside initialize method but it doesn't change the result:

btnGuardar.setOnAction(this::guardar);
btnMostrarInforme.setOnAction(this::generaInforme);

This is the JRDataSource class:

public class NotaDatasource implements JRDataSource {

    private List<Nota> listaNota = new ArrayList<Nota>();
    private int indiceNotaActual = -1;

    @Override
    public boolean next() throws JRException {
        return ++indiceNotaActual < listaNota.size();
    }

    @Override
    public Object getFieldValue(JRField jrf) throws JRException {
        Object valor = null;

        if ("dni".equals(jrf.getName())){
            valor=listaNota.get(indiceNotaActual).getNota();
        }
        else if ("asignatura".equals(jrf.getName())){
            valor=listaNota.get(indiceNotaActual).getAsignatura();
        }
        else if ("nota".equals(jrf.getName())){
            valor=listaNota.get(indiceNotaActual).getNota();
        }
        else if ("notaRecuperacion".equals(jrf.getName())){
            valor=listaNota.get(indiceNotaActual).getNotaRecuperacion();
        }

        return valor;
    }

    public void addNota(Nota nota) {
        this.listaNota.add(nota);
    }
}

And this is the Output exception:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8413)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    ... 48 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
    at di_t4.FXMLFichaAlumnoController.generaInforme(FXMLFichaAlumnoController.java:125)
    ... 58 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 60 more

At some point in the output, it says this:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
        at di_t4.FXMLFichaAlumnoController.generaInforme(FXMLFichaAlumnoController.java:125)

It refers to this line from FXMLController class, but I don't think this is the real issue:

JasperReport reporte = (JasperReport) JRLoader.loadObjectFromFile("InformeNotaAlumnos.jasper");

Sorry about this looooong post, if you can help me I'll be very happy.

Thanks!

Lal
  • 21
  • 4

0 Answers0