【问题标题】:Switching Views with Gluon Charm使用 Gluon Charm 切换视图
【发布时间】:2015-11-23 22:25:46
【问题描述】:

我正在尝试构建具有多个视图的应用程序。我已经成功添加了两个视图,但是当我尝试切换到第三个视图时出现错误:

Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at com.airhacks.afterburner.views.FXMLView.loadSynchronously(FXMLView.java:91)
at com.airhacks.afterburner.views.FXMLView.initializeFXMLLoader(FXMLView.java:100)
at com.airhacks.afterburner.views.FXMLView.getPresenter(FXMLView.java:179)
at com.testapp.gpa.TestApp.lambda$init$2(TestApp.java:46)
at com.testapp.gpa.TestApp.access$lambda$2(TestApp.java)
at com.testapp.gpa.TestApp$$Lambda$5.get(Unknown Source)
at com.gluonhq.impl.charm.a.d.a.a(SourceFile:32)
at com.gluonhq.charm.glisten.application.MobileApplication.switchView(SourceFile:344)
at com.gluonhq.charm.glisten.application.MobileApplication.switchView(SourceFile:312)

项目结构

我可以从主视图切换到学期视图。但我无法切换到 CourseView。视图只是扩展 FXMLView 类的空类。我正在关注 Comments 示例应用程序的项目结构。 这是 course.fxml 文件的第一行

<View maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.testapp.views.courses.CoursePresenter">

指向控制器类。

【问题讨论】:

  • Location is not set 表示当您尝试加载 fxml 文件时未找到它。请提供有关如何将其添加到项目中的更多详细信息(项目结构、文件名......)
  • 我编辑了这个问题。另外,你能解释一下项目结构的作用吗?我只是遵循了 Comments 示例应用程序的结构,我不知道 FXML、Presenter 和空 View 类是如何交互的。
  • 另一个重要提示:fxml 文件必须全部小写。它可以在 Windows 上运行,但在 linux 或 android 等区分大小写的操作系统上会失败。

标签: javafx javafxports gluon


【解决方案1】:

如果您遵循了 Comments 示例,有一个详细的 post 关于它,解释 Gluon 插件如何生成项目,以及您必须在哪里添加代码和资源。

还解释了如何使用Afterburner 框架。

由于它基于约定优于配置,因此对于像 home 这样的视图,您必须定义:

  • 在 src/main/java 目录下: com.gluonhq.demo.comments.views.home 包和两个类:HomeViewHomePresenter

  • 在 src/main/resources 目录中: com.gluonhq.demo.comments.views.home 包和两个文件:home.fxmlhome.css

在您的项目中,您有:homesemestercourse。请注意,您已经定义了CourseViewCoursePresenter,因此这是框架因Location is not set 异常而失败的原因:它期待course.fxml,但您添加了courses.fxml。因此,要么将类重命名为 CoursesViewCoursesPresenter,要么将 fxml 文件重命名为 course.fxml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多