0

我一直在尝试在 javafx 的 main 方法和 fxml 文件中的 anylayout 中添加 InlineStyleTextArea 和 CodeArea。我收到一个线程错误。如果可能的话,请举例说明如何将这些组件添加到 javafx 布局中?如果可能,请提供教程链接。

这是一个简单的代码

public class Main extends Application {

@Override

public void start(Stage primaryStage) {
TextField myTextField = new TextField();
InlineCssTextArea TextArea = new InlineCssTextArea();

  HBox hbox = new HBox();
hbox.getChildren().add(myTextField);
hbox.getChildren().add(TextArea);
HBox.setHgrow(myTextField, Priority.ALWAYS);
HBox.setHgrow(TextArea, Priority.ALWAYS);

Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();}

public static void main(String[] args) {
launch(args);


}

}

Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
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.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/reactfx/value/SuspendableVal
at application.Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/19776028.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/18503843.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/3799573.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/2180324.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/3326003.run(Unknown Source)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.reactfx.value.SuspendableVal
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
Exception running application application.Main

at com.sun.javafx.application.LauncherImpl$$Lambda$50/14845382.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
4

1 回答 1

1

从堆栈跟踪来看,Java 运行时似乎找不到(至少一个类)ReactFX 库,这是 RichTextFX 的依赖项。既然它一直在寻找它,它一定已经找到InlineCssTextArea了,所以必须安装 RichTextFX 库。

如果您使用某种依赖管理(例如 Gradle 或 Maven),该工具应该为您管理所有依赖。

如果您手动管理依赖项(即下载 jar 文件并将它们添加到类路径),则需要确保您也下载所有依赖的 jar 文件,或者使用“Fat jar 文件”

于 2016-01-07T17:07:26.063 回答