我有问题。在我的程序中,我有两个文本区域,下面有一个按钮。我想做这件事:我在一个文本区域写一些文本,同时在第二个区域打印反转文本。按钮将清除两个文本区域。我使用SceneBuilder,我创建了自己的方法,我在其中执行操作并在SceneBuilder中进行了更改 - 我将这些方法写入" Code"适合我的期望的地区。你能帮我解决这个错误吗?它显示
"线程中的异常" JavaFX应用程序线程" java.lang.IllegalArgumentException:参数类型不匹配"
但我认为变量的类型还可以。
控制器:
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();
}
完整堆栈跟踪:
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文件:
<?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>