【发布时间】: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