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

场景生成器没有重新连接我的Controller类

松灿
2023-03-14

我正在使用Intelij Idea在JAVAFX中尝试一个简单的项目,因此我遇到了两个问题:

案例1:

当我将sample.fxmlcontroller.javamain.java放在同一个文件夹src/main/java/fx/:

Parent root = FXMLLoader.load(getClass().getResource("/FX/sample.fxml"));

/opt/java/jdk1.8.0_20/bin/java -Didea.launcher.port=7537 -Didea.launcher.bin.path=/opt/idea-IU-143.381.42/bin -Dfile.encoding=UTF-8 -classpath /opt/java/jdk1.8.0_20/jre/lib/charsets.jar:/opt/java/jdk1.8.0_20/jre/lib/deploy.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/cldrdata.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/dnsns.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/jfxrt.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/localedata.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/nashorn.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/sunec.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/sunjce_provider.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/sunpkcs11.jar:/opt/java/jdk1.8.0_20/jre/lib/ext/zipfs.jar:/opt/java/jdk1.8.0_20/jre/lib/javaws.jar:/opt/java/jdk1.8.0_20/jre/lib/jce.jar:/opt/java/jdk1.8.0_20/jre/lib/jfr.jar:/opt/java/jdk1.8.0_20/jre/lib/jfxswt.jar:/opt/java/jdk1.8.0_20/jre/lib/jsse.jar:/opt/java/jdk1.8.0_20/jre/lib/management-agent.jar:/opt/java/jdk1.8.0_20/jre/lib/plugin.jar:/opt/java/jdk1.8.0_20/jre/lib/resources.jar:/opt/java/jdk1.8.0_20/jre/lib/rt.jar:/home/azb/IdeaProjects/TestMavenFX/target/classes:/opt/idea-IU-143.381.42/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain FX.Main

** (java:7837): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-MBNrjIF7ES: Connection refused
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
    at com.sun.javafx.application.LauncherImpl$$Lambda$1/424058530.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3201)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
    at FX.Main.start(Main.java:13)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
    at com.sun.javafx.application.LauncherImpl$$Lambda$55/669200515.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
    at com.sun.javafx.application.PlatformImpl$$Lambda$51/645218408.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
    at com.sun.javafx.application.PlatformImpl$$Lambda$53/222734631.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
    at com.sun.javafx.application.PlatformImpl$$Lambda$52/444279218.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$null$45(GtkApplication.java:126)
    at com.sun.glass.ui.gtk.GtkApplication$$Lambda$43/1060865646.run(Unknown Source)
    ... 1 more

Process finished with exit code 1

案例2:

当我将sample.fxml放在src/main/resources/fx/文件夹中,并将controller.javamain.java/fx/文件夹中:

1-SceneBuilder找不到Controller.java

谢谢

共有1个答案

呼延高超
2023-03-14

在fxml文件中定义控制器类:

<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="GridPane" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" fx:controller="yourpackage.yourControllerClass">
   <children>
     ...
   </children>
</AnchorPane>
 类似资料:
  • 我希望此图表显示在场景生成器上。怎么可能。。??

  • 我对屏幕生成器有一些问题 对于某些fxml,它会在加载后发生creash。我尝试了很多次运行它,但它阻塞了,我必须终止这个进程。 fxml正常,内容在我的应用程序中正确显示。下面是导致场景生成器崩溃的FXML示例。

  • 几个星期以来,我一直在想办法解决这个问题,现在我开始放弃了。我肯定做了什么根本错误的事情。不管怎样,这是我的情况。我以前用JavaFX做了一个简单的小程序,但现在发现了Scene Builder,并想用这个工具重新构建它。该项目包括几个经常重用的组件,如下面的组件。它由一个标签、一个滑块、一个文本字段和另一个自定义组件InfoIcon组成。 我已经了解到,在构建我称之为SliderVariable

  • 每当我试图从Intellij用scenebuilder打开一个fxml文件时,它会给我以下信息: (我已经从设置放入了场景构建器的路径)

  • 我正在用java开发一个聊天机器人项目,在GUI中我使用JavaFX、IDE eclipse和scene builder 8.4.1。 我在向文本区域添加背景图像时遇到问题。这是我所做的一个屏幕截图,它什么也没有显示(甚至没有错误)。 以下是场景生成器生成的fxml代码:

  • 我在Scene Builder for Java8中创建了。我的文件存储在中。我在中连接样式表,然后就可以了。但是在启动应用程序之后,我得到了错误的异常:。 怎么解决这个?我需要每次在中重命名路径到? 加载FXML: