0

This is my code, and i have a little problem with VOID HANDLECLICK()

public class UsoDataGraph implements Initializable {
    @FXML
    private BarChart<?, ?> statisticheChart;
    @FXML
    private CategoryAxis x;
    @FXML
    private NumberAxis y;

    @FXML
    private Parent root;

    //not important code!!

    @SuppressWarnings({ "rawtypes", "unchecked" })
    //@Override
    public void initialize(URL location, ResourceBundle resources)
    {
        ObservableList<VisualizzaStatistiche> proviamo = VisualizzaStatistiche.usoDate();
        XYChart.Series set1 = new XYChart.Series<>();
        for(int i = 0; i< proviamo.size(); i++)
        {  
            set1.getData().add(new XYChart.Data<>(proviamo.get(i).getData(), proviamo.get(i).getFrequenza()));
        }
        statisticheChart.getData().addAll(set1);

        Point p = MouseInfo.getPointerInfo().getLocation();
        System.out.println(p);


    }

    @FXML
    void handleClick(ActionEvent event) 
    {
        try {
            root = FXMLLoader.load(Main.class.getResource("view/VisStat.fxml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Main.getPrimaryStage().setScene(new Scene(root));
    }

The code of errors is this:

 //this is javafx view problems
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
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)
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.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$ClickGenerator.postProcess(Scene.java:3470)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
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)

So I think that the problem is in the scene, but I don't have any ideas.

fabian
  • 80,457
  • 12
  • 86
  • 114
Difettoso
  • 51
  • 1
  • 1
  • 10
  • 3
    Post the FXML file in the question. It looks like you are trying to use a method that takes an `ActionEvent` as its parameter for a mouse event handler. – James_D Feb 15 '18 at 22:09
  • 1
    Which event do you use `handleClick` for? Are you sure it's a `EventHandler`? `onMouseClicked` is a `EventHandler`... – fabian Feb 15 '18 at 22:10
  • Also note that inside your ``handleClick` method you probably need to call `root = FXMLLoader.load(Main.class.getResource("view/VisStat.fxml").toExternalForm());`. Are you suing an IDE like Eclipse or IntelliJ? An IDE can give you very useful hints on programming errors. – Markus Köbele Feb 15 '18 at 22:47
  • 1
    @MarkusK [`FXMLLoader.load(...)`](https://docs.oracle.com/javase/9/docs/api/javafx/fxml/FXMLLoader.html#load-java.net.URL-) takes a `URL`, not a `String`. If the type were wrong there, it simply wouldn't compile anyway - you wouldn't get to the stage of getting a runtime exception. – James_D Feb 15 '18 at 22:48
  • Oh, yes. You are right. I was referring to [this answer](https://stackoverflow.com/a/13759644/4240433), which seems to be not quite correct. I assume it felt right because I use the `toExternalForm()` very often when loading `.css` files. Thanks for your input. – Markus Köbele Feb 15 '18 at 22:58
  • 1
    @MarkusK Indeed, it's not quite correct. (Note the comments below the answer.) There are methods in JavaFX that take the string form of a URL (CSS stylesheets, as well as image locations), but here an actual `URL` is expected. – James_D Feb 15 '18 at 23:01

1 Answers1

0

This is the fxml code:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<BarChart fx:id="statisticheChart" onMouseClicked="#handleClick" title="Date più richieste" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dipalma.parcheggioautomatico.view.UsoDataGraph">
  <xAxis>
    <CategoryAxis label="data" side="BOTTOM" fx:id="x" />
  </xAxis>
  <yAxis>
    <NumberAxis fx:id="y" label="occupazione" side="LEFT" />
  </yAxis>
</BarChart>
Difettoso
  • 51
  • 1
  • 1
  • 10