当前位置: 首页 > 知识库问答 >
问题:

基本javafx scenebuilder fxml文件导致错误

鲁建茗
2023-03-14

我试图创建一个中间有几个选项卡的基本窗口,第一个选项卡包含一个表。

每次我运行主Java类时,它都会给我错误,甚至当我删除table和tab时也是如此。

下面是我的主要文件

package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.fxml.FXMLLoader;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

下面是我的fxml文件:

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

<?import com.gluonhq.charm.glisten.control.NavigationDrawer?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<BorderPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application/SampleController.java">
   <left>
      <GridPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" BorderPane.alignment="CENTER">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="580.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints maxHeight="81.0" minHeight="60.0" prefHeight="60.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="152.0" minHeight="60.0" prefHeight="60.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="420.0" minHeight="420.0" prefHeight="420.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="315.0" minHeight="180.0" prefHeight="180.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" GridPane.columnIndex="1" GridPane.rowIndex="2">
              <tabs>
                <Tab text="Untitled Tab 1">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                           <children>
                              <TableView editable="true" layoutX="109.0" layoutY="47.0" prefHeight="200.0" prefWidth="200.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                <columns>
                                  <TableColumn prefWidth="75.0" text="C1" />
                                  <TableColumn prefWidth="75.0" text="C2" />
                                </columns>
                              </TableView>
                           </children>
                        </AnchorPane>
                  </content>
                </Tab>
                <Tab text="Untitled Tab 2">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                  </content>
                </Tab>
              </tabs>
            </TabPane>
            <NavigationDrawer GridPane.columnIndex="1" GridPane.rowIndex="3" />
         </children>
      </GridPane>
   </left>
</BorderPane>

任何事都有帮助。我在这上面找不到任何东西,但可能是我的FXMLLoader.Load文件源吗?我真的不知道。

下面是我的错误代码:

javafx.fxml.LoadException: 
/C:/Users/_____/Desktop/AllJava/Java/SecAnalyzer/bin/application/Sample.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.importClass(Unknown Source)
    at javafx.fxml.FXMLLoader.processImport(Unknown Source)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:14)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.NavigationDrawer
    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)
    at javafx.fxml.FXMLLoader.loadTypeForPackage(Unknown Source)
    at javafx.fxml.FXMLLoader.loadType(Unknown Source)
    ... 21 more

安装gluon Mobile后出现新错误:

javafx.fxml.LoadException: 
/C:/Users/____/Desktop/AllJava/Java/SecAnalyzer/bin/application/Sample.fxml:14

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.access$700(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$Element.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at application.Main.start(Main.java:14)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: application/SampleController.java
    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)
    ... 23 more

共有1个答案

马坚白
2023-03-14

您的类路径中是否有NavigationDrawer.Class

原因:java.lang.ClassNotFoundException:com.gluonhq.charm.glisten.control.NavigationDrawer

在FXML文件中,您有:

<?import com.gluonhq.charm.glisten.control.NavigationDrawer?>

因此,您需要在类路径中包含NavigationDrawer.class才能正确加载FXML文档。

如果没有,您需要从GLUONHQ下载它。

 类似资料:
  • 这是密码 我希望一个包含2个元素的数组第一个是空字符串,第二个是“\test”,因为它在javascript中工作得非常好 但不是预期的输出,而是我如何获得完整的:( 不知道我做错了什么。。。

  • 我已经开始为一个个人项目学习JavaFX,事情进展顺利,直到我遇到了创建一组文本字段的问题。据我所知,代码是正确的,我使用的IDE没有给出任何错误指示。但当我尝试运行程序时,它会抛出一长串错误,这些错误在我注释创建文本字段的代码时不会发生。当这些代码行被省略时,程序将完全按照它应该的方式运行。 我正在使用InteliJ Idea,Windows 10,Javafx SDK 14.0.1和Java

  • 我正在尝试在我的ionic应用程序中实现推送通知。为此,我想使用本机插件Push: https://ionicframework.com/docs/native/push/ 在安装这个插件之前,我可以在我的Android设备上启动我的应用程序,使用: 我不能再运行我的设备上的应用程序,因为构建失败,因为一堆错误。 这个错误有一个建议:将'tools:replace=“android:value”‘

  • 我在Visual Studio 2015中升级到了Xamarin的最新版本。然后我编译了我的Android项目,遇到了以下错误: 无法访问android。应用程序。活动错误类文件:[驱动器]:[android sdk文件夹]\platforms\android-24\android。jar(android/app/Activity.class)类文件版本52.0错误,应为50.0。请删除或确保它出

  • 问题内容: 当我使用以下代码读取文件时: 我有以下错误 文件大小是 问题答案: 显然,文件太大,无法一次全部读入内存。 为什么不使用: 或者,如果您未使用Python 2.6和更高版本,则: 在这两种情况下,您都将获得一个迭代器,该迭代器可以像对待字符串列表一样对待。 编辑:由于您将整个文件读取为一个大字符串然后在换行符上进行拆分的方式将删除过程中的换行符,因此我在示例中添加了a ,以便更好地模拟

  • java.lang.nosuchmethoderror:org.springframework.boot.builder.springapplicationbuilder.([ljava/lang/object;)V在org.springframework.cloud.bootstrap.bootstrapapplicationlistener.bootstrapserviceContext(bo