0

FXML файл

<?language javascript?>

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.canvas.Canvas?>
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
      fx:controller="com.df.sandbox.HelloController">
    <padding>
        <Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
    </padding>

    <Label fx:id="welcomeText"/>
    <Button text="Hello!" onAction="buttonClick"/>
    <Canvas fx:id="mainCan"/>
    <fx:script>
        buttonClick = () => {
            welcomeText.setText("Oh, yea")
        }
    </fx:script>
</VBox>

POX.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.DF</groupId>
    <artifactId>sandBox</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>sandBox</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.8.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>18</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>18</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.df.sandbox/com.df.sandbox.HelloApplication</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

C:\Users\user.jdks\openjdk-18.0.1.1\bin\java.exe "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.2\lib\idea_rt.jar=57123:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\user.m2\repository\org\openjfx\javafx-controls\18\javafx-controls-18.jar;C:\Users\user.m2\repository\org\openjfx\javafx-graphics\18\javafx-graphics-18.jar;C:\Users\user.m2\repository\org\openjfx\javafx-base\18\javafx-base-18.jar;C:\Users\user.m2\repository\org\openjfx\javafx-fxml\18\javafx-fxml-18.jar -p "C:\Users\user.m2\repository\org\openjfx\javafx-controls\18\javafx-controls-18-win.jar;C:\Users\user\Desktop\Проекты JavaFX\sandBox\sandBox\target\classes;C:\Users\user.m2\repository\org\openjfx\javafx-graphics\18\javafx-graphics-18-win.jar;C:\Users\user.m2\repository\org\openjfx\javafx-fxml\18\javafx-fxml-18-win.jar;C:\Users\user.m2\repository\org\openjfx\javafx-base\18\javafx-base-18-win.jar" -m com.df.sandbox/com.df.sandbox.HelloApplication Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465) at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081) Caused by: java.lang.RuntimeException: Exception in Application start method at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901) at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: javafx.fxml.LoadException: /C:/Users/user/Desktop/�������%20JavaFX/sandBox/sandBox/target/classes/com/df/sandbox/hello-view.fxml

at javafx.fxml@18/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707) at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2650) at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) at javafx.fxml@18/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516) at com.df.sandbox/com.df.sandbox.HelloApplication.start(HelloApplication.java:19) at javafx.graphics@18/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847) at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484) at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at javafx.graphics@18/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456) at javafx.graphics@18/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at javafx.graphics@18/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at javafx.graphics@18/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184) ... 1 more Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,6] Message: The processing instruction target matching "[xX][mM][lL]" is not allowed. at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652) at java.xml/javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:84) at javafx.fxml@18/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2620) ... 12 more Exception running application com.df.sandbox.HelloApplication

И главное: даже если в скрипте ничего не будет написано, он всё равно выдаст ошибку. Без понятия, почему так. Надеюсь на вашу помощь.

1 ответ 1

0

Короче, я всё понял. Оказывается, строчка <?language javascript?> должна быть после строчки <?xml version="1.0" encoding="UTF-8"?>

1
  • В текущем виде ваш ответ непонятен. Пожалуйста, нажмите править под сообщением, чтобы добавить больше подробностей, которые помогут другим понять, как он отвечает на заданный вопрос. Вы можете найти больше информации о том, как писать хорошие ответы в Справке. 11 сен 2022 в 9:04

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.