线程异常 "JavaFX Application Thread" java.lang.IllegalArgumentException
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException
我正在使用 javafx 创建我的桌面应用程序。
当我尝试 运行 我的代码时,我不断收到此错误 -
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access00(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent5(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null9(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我没写fxml文件,我用的是SceneBuilder
我的 fxml -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTextArea?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="neviTracker.ui.ScannerController">
<children>
<VBox prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #ffffff;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox alignment="CENTER" prefHeight="56.0" prefWidth="600.0">
<children>
<Label text="Scanning" textAlignment="CENTER">
<font>
<Font name="System Bold Italic" size="29.0" />
</font>
</Label>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="53.0" prefWidth="575.0" spacing="5.0">
<children>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgDownload" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Download Images">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgProccessing" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Processing">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgClassify" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Classfiy">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="59.0" prefWidth="115.0">
<children>
<ImageView fx:id="imgDifference" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Check for difference">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgFinal" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Final steps">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
</children>
</HBox>
<ScrollPane prefHeight="250.0" prefWidth="600.0">
<content>
<JFXTextArea fx:id="txtProgress" maxWidth="594.0" minWidth="585.0" prefHeight="242.0" prefWidth="585.0" />
</content>
</ScrollPane>
<HBox alignment="CENTER" prefHeight="40.0" prefWidth="600.0" spacing="20.0">
<children>
<JFXButton fx:id="btnStartScanning" buttonType="RAISED" onAction="#handleStartButton" prefWidth="80.0" ripplerFill="WHITE" style="-fx-background-color: #408ea8;" text="Start" textFill="WHITE" />
<JFXButton fx:id="btnStopScanning" buttonType="RAISED" onAction="#handleStopButton" prefWidth="80.0" ripplerFill="WHITE" style="-fx-background-color: #408ea8;" text="Cancel" textFill="WHITE" />
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>
以及此 fxml 背后的代码 -
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextArea;
import emuns.ImageStatus;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import utils.Constants;
public class ScannerController implements Initializable {
@FXML
private ImageView imgDownload;
@FXML
private ImageView imgProccessing;
@FXML
private ImageView imgClassify;
@FXML
private ImageView imgDifference;
@FXML
private ImageView imgFinal;
@FXML
private JFXTextArea txtProgress;
@FXML
private JFXButton btnStartScanning;
@FXML
private JFXButton btnStopScanning;
Map<String, ImageView> mapping = new HashMap<>();
@FXML private FXMLDrawerController drawerController;
public ScannerController() {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
mapping.put("Downloading", imgDownload);
mapping.put("Processing", imgProccessing);
mapping.put("Classify", imgClassify);
mapping.put("Differance", imgDifference);
mapping.put("Final", imgFinal);
}
public void setDrawerController(FXMLDrawerController drawerController) {
this.drawerController = drawerController;
}
@FXML
void handleStartButton(MouseEvent event) {
drawerController.startScanning();
}
@FXML
void handleStopButton(MouseEvent event) {
drawerController.startScanning();
}
}
有人看到问题可以帮助我吗?
我不知道如何解决我的问题.. somwone 可以给我建议吗?
发送
使用ActionEvent
代替MouseEvent
@FXML
void handleStartButton(ActionEvent event) {
drawerController.startScanning();
}
@FXML
void handleStopButton(ActionEvent event) {
drawerController.startScanning();
}
我正在使用 javafx 创建我的桌面应用程序。 当我尝试 运行 我的代码时,我不断收到此错误 -
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access00(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent5(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null9(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我没写fxml文件,我用的是SceneBuilder
我的 fxml -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTextArea?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="neviTracker.ui.ScannerController">
<children>
<VBox prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #ffffff;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox alignment="CENTER" prefHeight="56.0" prefWidth="600.0">
<children>
<Label text="Scanning" textAlignment="CENTER">
<font>
<Font name="System Bold Italic" size="29.0" />
</font>
</Label>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="53.0" prefWidth="575.0" spacing="5.0">
<children>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgDownload" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Download Images">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgProccessing" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Processing">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgClassify" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Classfiy">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="59.0" prefWidth="115.0">
<children>
<ImageView fx:id="imgDifference" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Check for difference">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="53.0" prefWidth="109.0">
<children>
<ImageView fx:id="imgFinal" fitHeight="32.0" fitWidth="31.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../Images/waiting_icon.png" />
</image>
</ImageView>
<Label text="Final steps">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</VBox>
</children>
</HBox>
<ScrollPane prefHeight="250.0" prefWidth="600.0">
<content>
<JFXTextArea fx:id="txtProgress" maxWidth="594.0" minWidth="585.0" prefHeight="242.0" prefWidth="585.0" />
</content>
</ScrollPane>
<HBox alignment="CENTER" prefHeight="40.0" prefWidth="600.0" spacing="20.0">
<children>
<JFXButton fx:id="btnStartScanning" buttonType="RAISED" onAction="#handleStartButton" prefWidth="80.0" ripplerFill="WHITE" style="-fx-background-color: #408ea8;" text="Start" textFill="WHITE" />
<JFXButton fx:id="btnStopScanning" buttonType="RAISED" onAction="#handleStopButton" prefWidth="80.0" ripplerFill="WHITE" style="-fx-background-color: #408ea8;" text="Cancel" textFill="WHITE" />
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>
以及此 fxml 背后的代码 -
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextArea;
import emuns.ImageStatus;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import utils.Constants;
public class ScannerController implements Initializable {
@FXML
private ImageView imgDownload;
@FXML
private ImageView imgProccessing;
@FXML
private ImageView imgClassify;
@FXML
private ImageView imgDifference;
@FXML
private ImageView imgFinal;
@FXML
private JFXTextArea txtProgress;
@FXML
private JFXButton btnStartScanning;
@FXML
private JFXButton btnStopScanning;
Map<String, ImageView> mapping = new HashMap<>();
@FXML private FXMLDrawerController drawerController;
public ScannerController() {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
mapping.put("Downloading", imgDownload);
mapping.put("Processing", imgProccessing);
mapping.put("Classify", imgClassify);
mapping.put("Differance", imgDifference);
mapping.put("Final", imgFinal);
}
public void setDrawerController(FXMLDrawerController drawerController) {
this.drawerController = drawerController;
}
@FXML
void handleStartButton(MouseEvent event) {
drawerController.startScanning();
}
@FXML
void handleStopButton(MouseEvent event) {
drawerController.startScanning();
}
}
有人看到问题可以帮助我吗? 我不知道如何解决我的问题.. somwone 可以给我建议吗? 发送
使用ActionEvent
代替MouseEvent
@FXML
void handleStartButton(ActionEvent event) {
drawerController.startScanning();
}
@FXML
void handleStopButton(ActionEvent event) {
drawerController.startScanning();
}