在 javaFX 8 中添加 Button 节点会引发异常 - javafx.fxml.LoadException:无效标识符

Ste*_*ail 1 java exception intellij-idea fxml javafx-8

我在创建的 StackPane 布局中添加了两个图像视图,但是当我尝试在 StackPane 布局中添加按钮节点时,虽然图像工作得很好,但按钮不允许程序运行并抛出此错误我无法弄清楚的例外:

> > Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Invalid identifier.
/C:/Users/Steli/Dropbox/Java_Projects/IntelliJ%20IDEA%20Projects/DokkanCardsPreview/out/production/DokkanCardsPreview/fxml/home.fxml:33
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:901)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at com.spdesigns.dokkancardspreview.Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application com.spdesigns.dokkancardspreview.Main

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

现在这是我的 fxml 文件:

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

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<GridPane xmlns="http://javafx.com/javafx"
          xmlns:fx="http://javafx.com/fxml"
          fx:controller="com.spdesigns.dokkancardspreview.controllers.home"
          stylesheets="/css/main.css"
          fx:id="container"
          prefHeight="400.0" prefWidth="600.0">

    <children>
        <Label text="Cards List" fx:id="listTitle" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
        <HBox fx:id="listViewAndImageContainer">
                <children>
                    <ListView fx:id="listView" GridPane.rowIndex="1" GridPane.columnIndex="0" prefHeight="600"/>
                </children>
            <children>
                <StackPane fx:id="ImageAndArrowButtonContainer">
                    <children>
                        <ImageView fx:id="imageView" fitWidth="400" fitHeight="600">
                           <Image url="/images/image_placeholder.png" fx:id="image"/>
                        </ImageView>
                        <ImageView fx:id="arrow" fitHeight="40" fitWidth="60">
                            <Image url="/images/arrow.png"/>
                        </ImageView>
                        <Button fx:id="arrow-button" prefHeight="40" prefWidth="60"  text="test"></Button>
                    </children>
                </StackPane>
            </children>
        </HBox>
    </children>

</GridPane>
Run Code Online (Sandbox Code Playgroud)

这是 main.java-粘贴它,因为它在异常中提到了-:

package com.spdesigns.dokkancardspreview;

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("/fxml/home.fxml"));
        primaryStage.setTitle("Dokkan Battle Card Preview");
        primaryStage.setScene(new Scene(root, 900, 700));
        primaryStage.setResizable(false);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
     }
}
Run Code Online (Sandbox Code Playgroud)

希望这里有人可以帮助我解决这个问题(这可能是一些“愚蠢”的事情,但仍然......我似乎找不到这个异常的解决方案!

Nab*_*ari 5

id 中不能使用破折号 (-),因为它表示减号运算。将其替换为下划线(_) 或使用驼峰命名法。