当前位置: 首页 > 面试题库 >

JavaFx事件参数类型不匹配

郝修为
2023-03-14
问题内容

我第一次使用JavaFx,遇到事件问题。我用SceneBuilder构建了一个表单,并在.fxml和controller上添加了一个事件,但始终返回:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch

FirstScene.fxml:

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" styleClass="background" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="examlog.gui.FirstSceneController">
    <stylesheets>
        <URL value="@dark_style.css" />
    </stylesheets>
   <children>
      <TableView fx:id="firstScene_tableView" layoutX="30.0" layoutY="42.0" prefHeight="287.0" prefWidth="600.0" AnchorPane.bottomAnchor="71.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="42.0">
        <columns>
          <TableColumn text="C1" />
          <TableColumn prefWidth="70.0" text="C2" />
        </columns>
      </TableView>
      <Label layoutX="14.0" layoutY="14.0" text="Létrehozott munkafolyamatok:" />
      <Button fx:id="firstScene_newbutton" layoutX="522.0" layoutY="353.0" mnemonicParsing="false" onMouseClicked="#newButtonClick" text="ÚJ" />
   </children>
</AnchorPane>

FirstSceneController.java:

public class FirstSceneController implements Initializable {

    @FXML 
    private Button firstScene_newbutton;
    @FXML 
    private TableView firstScene_tableView;

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {

    }

@FXML 
    private void newButtonClick(ActionEvent event) {
        System.out.println("You clicked me!");

    }



}

JavaFxApplication.java:

public class JavaFXApplication extends Application {

    private Stage stage;

    @Override
    public void start(Stage primaryStage) {
        this.stage = primaryStage;
        try {
            FirstScene();
            primaryStage.setTitle("FXML is Simple");
            primaryStage.show();
        } catch (IOException ex) {
            Logger.getLogger(JavaFXApplication.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void FirstScene() throws IOException {
        AnchorPane page = (AnchorPane) FXMLLoader.load(JavaFXApplication.class.getResource("FirstScene.fxml"));
        Scene scene = new Scene(page);
        stage.setScene(scene);

    }

}

例外:

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:483)
    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:483)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1757)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1645)
    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:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3437)
    at javafx.scene.Scene$ClickGenerator.access$7900(Scene.java:3365)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3733)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
    at com.sun.glass.ui.View.notifyMouse(View.java:925)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
    at com.sun.glass.ui.win.WinApplication$$Lambda$38/14271771.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)

我将非常感谢您的帮助。


问题答案:

使用onAction="#newButtonClick",而不是onMouseClicked



 类似资料:
  • 它打印出值的等效,这是因为这一行: 通过调用表示。 那么,如何使Hibernate相信是的实例? 我的枚举是由加载的。而由URLClassLoader加载,由另一个类加载器加载。

  • 当我想跑的时候: 我得到: 执行操作“MappingAddAction”的服务异常,java.lang.IllegalArgumentException:参数值[5118]与预期的类型[com.vernuso.trust.server.domain.ClientImport.MappingInfo(N/A)]不匹配 有人能帮助我理解为什么它需要类型而不是类型吗? 我有两个表,如下图所示。Mappi

  • 我做错了什么? 正在更新: 我发现了问题所在。问题与ActionRepository中找到的函数有关。函数的签名首先要求两个日期进行比较,然后id和我给出了相反的值。我很清楚,在我上了它之后,我会有一个问题的日期,所以答案确实帮助了我。谢谢大家!

  • 我得到的错误. 我对此感到困惑,因为它来自下面显示的被注释掉的服务方法。当我把它注释掉时,错误就避免了。列是一个,即或。 实体: 我的存储库: 我的服务: 当我取消注释时

  • 这是我运行程序时收到的错误: 注:[19533]是我使用的一个测试值。 这是在CustomerServiceBeanImpl.java中出现错误的方法: 在快速检查ERD时,“Customer”表中的“id”列的数据类型为bigint。然而,我不确定这是否重要。(顺便提一下PostgreSQL数据库。) 如何修复此错误?