0

I have a problem. In my program I have two text areas and one button below them. I want to do this thing: I write some text in one of text areas and at the same time it is printing reversed text in second area. Button would clear both text areas. I do it with SceneBuilder, I created my own methods where I perform actions and also made changes in SceneBuilder- I wrote this methods into fields in "Code" area that fit my expectations. Can you help me solve this mistake? It shows

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

But I think that the type of variables is okay.

Controller:

import javafx.event.ActionEvent;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

public class MainController {

@FXML
private TextArea baseTextArea;

@FXML
private TextArea reversedTextArea;

@FXML
private Button reverseTextButton;

@FXML
private void reverseTextAction(ActionEvent event) {
    StringBuilder str = new StringBuilder();
    str.append(baseTextArea.getText());
    reversedTextArea.setText(str.toString());
}

@FXML
private void reverseTextAction2(ActionEvent event) {
    StringBuilder str = new StringBuilder();
    str.append(reversedTextArea.getText());
    baseTextArea.setText(str.toString());
}

@FXML
private void clearTextAction(ActionEvent event) {
    baseTextArea.clear();
    reversedTextArea.clear();
}

Full stack trace:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.reflect.Trampoline.invoke(Unknown Source)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(Unknown Source)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Unknown Source)
at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1600(Unknown Source)
at javafx.graphics/javafx.scene.Scene.processKeyEvent(Unknown Source)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(Unknown Source)
at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(Unknown Source)
at javafx.graphics/com.sun.glass.ui.View.notifyKey(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

FXML File:

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

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" 
minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" 
xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="pl.borynka.controller.MainController">
<children>
  <HBox prefHeight="375.0" prefWidth="600.0">
     <children>
        <TextArea fx:id="baseTextArea" onKeyReleased="#reverseTextAction" 
prefHeight="200.0" prefWidth="300.0" />
        <TextArea fx:id="reversedTextArea" 
onKeyReleased="#reverseTextAction2" prefHeight="200.0" prefWidth="300.0" />
     </children>
  </HBox>
  <Button fx:id="reverseTextButton" maxWidth="1.7976931348623157E308" 
mnemonicParsing="false" onAction="#clearTextAction" text="Wyczyść" />
</children>
</VBox>
boratocielli
  • 129
  • 5

0 Answers0