线程“JavaFX Application Thread”中的异常java.lang.IllegalArgumentException

时间:2017-05-17 18:35:23

标签: java javafx scenebuilder illegalargumentexception

我正在使用javafx来创建我的桌面应用程序。 当Itried运行我的代码时,我不断收到此错误 -

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$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.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.access$1500(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$handleMouseEvent$355(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$null$149(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>

和代码behoynd这个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可以给我的建议吗? Tnx

1 个答案:

答案 0 :(得分:1)

使用from turtle import Turtle, Screen ANGLE = 90 DISTANCE = 10 def k1(): yertle.forward(DISTANCE) moves.append(1) def k2(): yertle.left(ANGLE) moves.append(2) def k3(): yertle.right(ANGLE) moves.append(3) def k4(): yertle.backward(DISTANCE) moves.append(4) COMMANDS = {1: k1, 2: k2, 3: k3, 4: k4} def save(): if moves and input('Would you like to save this drawing? (y/n) ').lower().startswith('y'): name = input('What would you like to call your drawing? ') with open(name, 'w') as my_file: print(*moves, sep=', ', file=my_file) print('Drawing has been saved as:', name) def clear(): global moves save() if moves and input('Would you like to erase this drawing? (y/n) ').lower().startswith('y'): moves = [] yertle.reset() def load(): clear() if input('Would you like to load a drawing? (y/n) ').lower().startswith('y'): name = input('What would drawing would you like to load? ') with open(name) as my_file: commands = [int(digit) for digit in my_file.readline().split(',')] for command in commands: if command in COMMANDS: COMMANDS[command]() print('Drawing has been loaded from:', name) screen = Screen() screen.setup(500, 500) screen.title('Turtle Art') moves = [] yertle = Turtle('turtle') screen.onkey(k1, 'Up') # move forwards screen.onkey(k2, 'Left') # turn left screen.onkey(k3, 'Right') # turn right screen.onkey(k4, 'Down') # move backwards screen.onkey(clear, 'c') # clear page screen.onkey(save, 'p') # save page screen.onkey(load, 'l') # load page screen.listen() screen.mainloop() 代替ActionEvent

MouseEvent
相关问题