Я начинаю свой путь с JavaFXml, и у меня проблема с компиляцией моей программы. Компилятор покажет мне проблему, и у меня нет никакой идеи, чтобы решить эту проблему.
Мой класс Mine:
package com.biku.readerFX;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Мой класс контроллера:
package com.biku.readerFX;
public class Controller {
}
Мой файл sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml"
fx:controller="com.biku.readerFX.Controller">
<Label text="I love bacon"/>
<Button text="Submit"/>
</VBox>
И когдаЯ компилирую это, компилятор показывает мне ошибки:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java --module-path /home/biku/Pobrane/openjfx-13/javafx-sdk-13/lib --add-modules javafx.controls,javafx.fxml --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED -javaagent:/snap/intellij-idea-community/177/lib/idea_rt.jar=41763:/snap/intellij-idea-community/177/bin -Dfile.encoding=UTF-8 -classpath /home/biku/IdeaProjects/WordReader/target/classes:/usr/lib/jvm/java-1.11.0-openjdk-amd64:/home/biku/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.jar:/home/biku/.m2/repository/org/apache/maven/maven-plugin-api/3.0/maven-plugin-api-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-model/3.0/maven-model-3.0.jar:/home/biku/.m2/repository/org/sonatype/sisu/sisu-inject-plexus/1.4.2/sisu-inject-plexus-1.4.2.jar:/home/biku/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar:/home/biku/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar:/home/biku/.m2/repository/org/apache/maven/maven-artifact/3.0/maven-artifact-3.0.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.4/plexus-utils-2.0.4.jar:/home/biku/.m2/repository/org/apache/maven/maven-core/3.0/maven-core-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-settings/3.0/maven-settings-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-settings-builder/3.0/maven-settings-builder-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-repository-metadata/3.0/maven-repository-metadata-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-model-builder/3.0/maven-model-builder-3.0.jar:/home/biku/.m2/repository/org/apache/maven/maven-aether-provider/3.0/maven-aether-provider-3.0.jar:/home/biku/.m2/repository/org/sonatype/aether/aether-impl/1.7/aether-impl-1.7.jar:/home/biku/.m2/repository/org/sonatype/aether/aether-spi/1.7/aether-spi-1.7.jar:/home/biku/.m2/repository/org/sonatype/aether/aether-api/1.7/aether-api-1.7.jar:/home/biku/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-classworlds/2.2.3/plexus-classworlds-2.2.3.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar:/home/biku/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar:/home/biku/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar:/home/biku/.m2/repository/org/apache/maven/shared/maven-shared-utils/3.2.1/maven-shared-utils-3.2.1.jar:/home/biku/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar:/home/biku/.m2/repository/org/apache/maven/shared/maven-shared-incremental/1.1/maven-shared-incremental-1.1.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar:/home/biku/.m2/repository/org/ow2/asm/asm/6.2/asm-6.2.jar:/home/biku/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M8/qdox-2.0-M8.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.8.4/plexus-compiler-api-2.8.4.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/2.8.4/plexus-compiler-manager-2.8.4.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar:/home/biku/.m2/repository/org/openjfx/javafx-controls/12.0.2/javafx-controls-12.0.2.jar:/home/biku/.m2/repository/org/openjfx/javafx-controls/12.0.2/javafx-controls-12.0.2-linux.jar:/home/biku/.m2/repository/org/openjfx/javafx-graphics/12.0.2/javafx-graphics-12.0.2.jar:/home/biku/.m2/repository/org/openjfx/javafx-graphics/12.0.2/javafx-graphics-12.0.2-linux.jar:/home/biku/.m2/repository/org/openjfx/javafx-base/12.0.2/javafx-base-12.0.2.jar:/home/biku/.m2/repository/org/openjfx/javafx-base/12.0.2/javafx-base-12.0.2-linux.jar:/home/biku/.m2/repository/org/openjfx/javafx-fxml/13/javafx-fxml-13.jar:/home/biku/.m2/repository/org/openjfx/javafx-fxml/13/javafx-fxml-13-linux.jar:/home/biku/.m2/repository/org/openjfx/javafx-maven-plugin/0.0.3/javafx-maven-plugin-0.0.3.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-archiver/3.6.0/plexus-archiver-3.6.0.jar:/home/biku/.m2/repository/org/codehaus/plexus/plexus-io/3.0.1/plexus-io-3.0.1.jar:/home/biku/.m2/repository/org/apache/commons/commons-compress/1.16.1/commons-compress-1.16.1.jar:/home/biku/.m2/repository/org/objenesis/objenesis/2.6/objenesis-2.6.jar:/home/biku/.m2/repository/org/iq80/snappy/snappy/0.4/snappy-0.4.jar:/home/biku/.m2/repository/org/tukaani/xz/1.8/xz-1.8.jar:/home/biku/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/home/biku/.m2/repository/org/twdata/maven/mojo-executor/2.3.0/mojo-executor-2.3.0.jar:/home/biku/.m2/repository/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.jar:/home/biku/.m2/repository/org/slf4j/slf4j-simple/1.7.22/slf4j-simple-1.7.22.jar com.biku.readerFX.Main
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
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:834)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3230)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at com.biku.readerFX.Main.start(Main.java:13)
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:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application com.biku.readerFX.Main
Process finished with exit code 1
Я пытаюсь решить это, как на этой странице:
И добавить путь к параметрам виртуальной машины в fx: --module-path $ {PATH_TO_FX} --add-modules javafx.controls, javafx.fxml
Добавить javafx как lib в проект.
У вас есть идеи, чтобы помочь мне? ТНХ