Mine Rockers Mine Rockers - 1 month ago 12
Java Question

JavaFX java.lang.IllegalArgumentException: argument type mismatch [scene builder]

I'm using Scene Builder for my Java FXML.

When I run the code, on startup, an IllegalArgumentException is seen, but the program continues to run perfectly.

This is the Controller, mostly generated by Scene Builder (sample controller skeleton).

FXMLDocumentController:

package minerocker_batch_ide_2;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;

public class FXMLDocumentController implements Initializable {

public int currentTab;

@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;

@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;

@FXML // fx:id="code4"
private TextArea code4; // Value injected by FXMLLoader

@FXML // fx:id="code3"
private TextArea code3; // Value injected by FXMLLoader

@FXML // fx:id="code2"
private TextArea code2; // Value injected by FXMLLoader

@FXML // fx:id="fileName"
private TextField fileName; // Value injected by FXMLLoader

@FXML // fx:id="code1"
private TextArea code1; // Value injected by FXMLLoader

@FXML // fx:id="saveAs"
private MenuItem saveAs; // Value injected by FXMLLoader

@FXML // fx:id="tab3"
private Tab tab3; // Value injected by FXMLLoader

@FXML // fx:id="save"
private MenuItem save; // Value injected by FXMLLoader

@FXML // fx:id="about"
private MenuItem about; // Value injected by FXMLLoader

@FXML // fx:id="tab4"
private Tab tab4; // Value injected by FXMLLoader

@FXML // fx:id="tab1"
private Tab tab1; // Value injected by FXMLLoader

@FXML // fx:id="run"
private Button run; // Value injected by FXMLLoader

@FXML // fx:id="tab2"
private Tab tab2; // Value injected by FXMLLoader

@FXML // fx:id="code5"
private TextArea code5; // Value injected by FXMLLoader

@FXML // fx:id="errorMsg"
private Button errorMsg; // Value injected by FXMLLoader

@FXML // fx:id="tab5"
private Tab tab5; // Value injected by FXMLLoader

@FXML // fx:id="lines"
private Text lines; // Value injected by FXMLLoader

@FXML // fx:id="newN"
private MenuItem newN; // Value injected by FXMLLoader

@FXML // fx:id="close"
private MenuItem close; // Value injected by FXMLLoader

@FXML
void change1(ActionEvent event) {

}

@FXML
void change2(ActionEvent event) {

}

@FXML
void change3(ActionEvent event) {

}

@FXML
void change4(ActionEvent event) {

}

@FXML
void change5(ActionEvent event) {

}

@FXML
void newNOnAction(ActionEvent event) {

}

@FXML
void saveOnAction(ActionEvent event) {

}

@FXML
void saveAsOnAction(ActionEvent event) {

}

@FXML
void closeOnAction(ActionEvent event) {

}

@FXML
void aboutOnAction(ActionEvent event) {

}

@FXML
void fileNameOnAction(ActionEvent event) {

}

@FXML
void runOnAction(ActionEvent event) {

}

@FXML
void errorMsgOnAction(ActionEvent event) {

}

@Override
public void initialize(URL url, ResourceBundle rb) {

}

}


FXMLDocument:

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

<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="minerocker_batch_ide_2.FXMLDocumentController">
<top>
<VBox prefHeight="72.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="newN" mnemonicParsing="false" onAction="#newNOnAction" text="New Ctrl + N" />
<MenuItem fx:id="save" mnemonicParsing="false" onAction="#saveOnAction" text="Save (none)" />
<MenuItem fx:id="saveAs" mnemonicParsing="false" onAction="#saveAsOnAction" text="Save As Ctrl + S" />
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#closeOnAction" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="about" mnemonicParsing="false" onAction="#aboutOnAction" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<ToolBar prefHeight="40.0" prefWidth="200.0">
<items>
<TextField fx:id="fileName" onAction="#fileNameOnAction" prefHeight="31.0" prefWidth="147.0" promptText="File Name" />
<Button fx:id="run" mnemonicParsing="false" onAction="#runOnAction" text="Run" />
<Pane prefHeight="0.0" prefWidth="38.0" />
<Button fx:id="errorMsg" mnemonicParsing="false" onAction="#errorMsgOnAction" text="Show Error Message" />
</items>
</ToolBar>
</children>
</VBox>
</top>
<bottom>
<HBox prefHeight="0.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Lines:" />
<Pane prefHeight="21.0" prefWidth="3.0" />
<Text fx:id="lines" strokeType="OUTSIDE" strokeWidth="0.0" text="0" />
</children>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</HBox>
</bottom>
<center>
<GridPane prefHeight="315.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="tab1" onSelectionChanged="#change1" text="Untitled Tab 1">
<content>
<TextArea fx:id="code1" prefHeight="200.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="tab2" onSelectionChanged="#change2" text="Untitled Tab 2">
<content>
<TextArea fx:id="code2" prefHeight="200.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="tab3" onSelectionChanged="#change3" text="Untitled Tab 3">
<content>
<TextArea fx:id="code3" prefHeight="200.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="tab4" onSelectionChanged="#change4" text="Untitled Tab 4">
<content>
<TextArea fx:id="code4" prefHeight="200.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="tab5" onSelectionChanged="#change5" text="Untitled Tab 5">
<content>
<TextArea fx:id="code5" prefHeight="200.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</GridPane>
</center>
</BorderPane>


Error:

Executing C:\Users\21114693\Documents\NetBeansProjects\MineRocker_Batch_IDE_2\dist\run324064419\MineRocker_Batch_IDE_2.jar using platform C:\Program Files\Java\jdk1.8.0_102\jre/bin/java
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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
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.control.Tab$1.invalidated(Tab.java:209)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
at javafx.scene.control.Tab.setSelected(Tab.java:185)
at javafx.scene.control.TabPane$TabPaneSelectionModel.select(TabPane.java:722)
at javafx.scene.control.TabPane$TabPaneSelectionModel.select(TabPane.java:735)
at javafx.scene.control.TabPane$TabPaneSelectionModel.findNearestAvailableTab(TabPane.java:794)
at javafx.scene.control.TabPane$TabPaneSelectionModel.lambda$new$17(TabPane.java:691)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:155)
at java.util.AbstractList.add(AbstractList.java:108)
at javafx.fxml.FXMLLoader$Element.add(FXMLLoader.java:168)
at javafx.fxml.FXMLLoader$PropertyElement.add(FXMLLoader.java:1403)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:788)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at minerocker_batch_ide_2.MineRocker_Batch_IDE_2.start(MineRocker_Batch_IDE_2.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
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)
Deleting directory C:\Users\21114693\Documents\NetBeansProjects\MineRocker_Batch_IDE_2\dist\run324064419
jfxsa-run:
BUILD SUCCESSFUL (total time: 16 seconds)

Answer

The problem is with your event handlers.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.text.Text;

public class FXMLDocumentController implements Initializable {

    public int currentTab;

    @FXML // ResourceBundle that was given to the FXMLLoader
    private ResourceBundle resources;

    @FXML // URL location of the FXML file that was given to the FXMLLoader
    private URL location;

    @FXML // fx:id="code4"
    private TextArea code4; // Value injected by FXMLLoader

    @FXML // fx:id="code3"
    private TextArea code3; // Value injected by FXMLLoader

    @FXML // fx:id="code2"
    private TextArea code2; // Value injected by FXMLLoader

    @FXML // fx:id="fileName"
    private TextField fileName; // Value injected by FXMLLoader

    @FXML // fx:id="code1"
    private TextArea code1; // Value injected by FXMLLoader

    @FXML // fx:id="saveAs"
    private MenuItem saveAs; // Value injected by FXMLLoader

    @FXML // fx:id="tab3"
    private Tab tab3; // Value injected by FXMLLoader

    @FXML // fx:id="save"
    private MenuItem save; // Value injected by FXMLLoader

    @FXML // fx:id="about"
    private MenuItem about; // Value injected by FXMLLoader

    @FXML // fx:id="tab4"
    private Tab tab4; // Value injected by FXMLLoader

    @FXML // fx:id="tab1"
    private Tab tab1; // Value injected by FXMLLoader

    @FXML // fx:id="run"
    private Button run; // Value injected by FXMLLoader

    @FXML // fx:id="tab2"
    private Tab tab2; // Value injected by FXMLLoader

    @FXML // fx:id="code5"
    private TextArea code5; // Value injected by FXMLLoader

    @FXML // fx:id="errorMsg"
    private Button errorMsg; // Value injected by FXMLLoader

    @FXML // fx:id="tab5"
    private Tab tab5; // Value injected by FXMLLoader

    @FXML // fx:id="lines"
    private Text lines; // Value injected by FXMLLoader

    @FXML // fx:id="newN"
    private MenuItem newN; // Value injected by FXMLLoader

    @FXML // fx:id="close"
    private MenuItem close; // Value injected by FXMLLoader

    @FXML
    void change1(Event event) {

    }

    @FXML
    void change2(Event event) {

    }

    @FXML
    void change3(Event event) {

    }

    @FXML
    void change4(Event event) {

    }

    @FXML
    void change5(Event event) {

    }

    @FXML
    void newNOnAction(ActionEvent event) {

    }

    @FXML
    void saveOnAction(ActionEvent event) {

    }

    @FXML
    void saveAsOnAction(ActionEvent event) {

    }

    @FXML
    void closeOnAction(ActionEvent event) {

    }

    @FXML
    void aboutOnAction(ActionEvent event) {

    }

    @FXML
    void fileNameOnAction(KeyEvent event) {

    }

    @FXML
    void runOnAction(ActionEvent event) {

    }

    @FXML
    void errorMsgOnAction(ActionEvent event) {

    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {

    }

}

Some ActionEvents should be Event or KeyEvent. Make keyEvent change in Scenebuilder from ActionEvent to Keypressed or keyreleased. Your On selection change should be Event.

Comments