1

我的构建配置

这是我的代码:

    MenuBar menuBar = new MenuBar();
    Menu menu1 = new Menu("File");
    Menu menu2 = new Menu("Edit");
    Menu menu3 = new Menu("Project");
    Menu menu4 = new Menu("Window");
    Menu menu5 = new Menu("Help");

    menuBar.getMenus().add(menu1);
    menuBar.getMenus().add(menu2);
    menuBar.getMenus().add(menu3);
    menuBar.getMenus().add(menu4);
    menuBar.getMenus().add(menu5);

    BorderPane borderPane = new BorderPane();
    HBox statusbar = new HBox();
    TabPane tabPane = new TabPane();


    CodeArea codeArea = new CodeArea();
    codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
    codeArea.replaceText(0, 0, sampleCode);


    Tab tab1 = new Tab("Untitled", codeArea);
    tabPane.getTabs().add(tab1);
    borderPane.setTop(menuBar);
    borderPane.setCenter(tabPane);
    borderPane.setBottom(statusbar);

    Scene scene = new Scene(borderPane);
    stage.setScene(scene);
    stage.setMaximized(true);
    stage.setTitle("Gooye");
    stage.show();

这些是我收到的所有错误(我使用的是 Java 15、fat jar 文件、javafx 16)

   Exception in Application start method
    java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
    Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
        at java.base/java.lang.Thread.run(Thread.java:832)
    Caused by: java.lang.IllegalAccessError: class org.fxmisc.richtext.TextFlowExt (in unnamed module @0x47fe7806) cannot access class com.sun.javafx.text.PrismTextLayout (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.text to unnamed module @0x47fe7806
        at org.fxmisc.richtext.TextFlowExt.<clinit>(TextFlowExt.java:35)
        at org.fxmisc.richtext.ParagraphBox.<init>(ParagraphBox.java:77)
        at org.fxmisc.richtext.GenericStyledArea.createCell(GenericStyledArea.java:1176)
        at org.fxmisc.richtext.GenericStyledArea.lambda$new$3(GenericStyledArea.java:611)
        at org.fxmisc.flowless.CellPool.getCell(CellPool.java:20)
        at org.fxmisc.flowless.CellListManager.cellForItem(CellListManager.java:75)
        at org.reactfx.collection.MappedList.get(MappedList.java:27)
        at org.reactfx.collection.MemoizationListImpl.get(MemoizationList.java:99)
        at org.fxmisc.flowless.CellListManager.getCell(CellListManager.java:64)
        at org.fxmisc.flowless.CellPositioner.getSizedCell(CellPositioner.java:129)
        at org.fxmisc.flowless.CellPositioner.placeStartAt(CellPositioner.java:95)
        at org.fxmisc.flowless.Navigator.placeStartAtMayCrop(Navigator.java:183)
        at org.fxmisc.flowless.Navigator.visit(Navigator.java:111)
        at org.fxmisc.flowless.StartOffStart.accept(TargetPosition.java:49)
        at org.fxmisc.flowless.Navigator.layoutChildren(Navigator.java:67)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
        at org.fxmisc.flowless.VirtualFlow.layoutChildren(VirtualFlow.java:165)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1207)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
        at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1214)
        at javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)
        at javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1750)
        at javafx.graphics/javafx.scene.Scene$2.preferredSize(Scene.java:393)
        at javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
        at javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1111)
        at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
        at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
        at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1187)
        at javafx.graphics/javafx.stage.Window.show(Window.java:1202)
        at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
        at sample.Main.start(Main.java:147)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    Exception running application sample.Main
4

1 回答 1

-1

尝试使用richtextfx 的胖JAR 文件(包括依赖项)。这是其 repo 的链接https://github.com/FXMisc/RichTextFX#download和下载 fat jar 文件的链接。

这对我来说很好。希望这也适用于你。

于 2021-11-17T04:19:34.493 回答