我发现了JAVAFX,并实现了项目结构的重构
1小时后,也许这很愚蠢,但实际上我不明白问题所在。
在围绕名称和包文件进行重构之前,它可以正常工作。
我的项目现在处于Maven之下(我不知道这是否有所改变)
这是我的错误:
GRAVE: null
io.datafx.controller.flow.FlowException: io.datafx.controller.FxmlLoadException: java.lang.reflect.InvocationTargetException
at io.datafx.controller.flow.FlowHandler.start(FlowHandler.java:143)
at io.datafx.controller.flow.FlowHandler.start(FlowHandler.java:101)
at maxiRename.controller.MainController.initialize(MainController.java:88)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at io.datafx.controller.ViewFactory.createByController(ViewFactory.java:161)
at io.datafx.controller.flow.FlowHandler.start(FlowHandler.java:140)
at maxiRenameApp.MainMaxiFilm.start(MainMaxiFilm.java:27)
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)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.datafx.controller.FxmlLoadException: java.lang.reflect.InvocationTargetException
at io.datafx.controller.ViewFactory.createByController(ViewFactory.java:180)
at io.datafx.controller.flow.FlowHandler.start(FlowHandler.java:140)
... 17 more
Caused by: 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 io.datafx.controller.ViewFactory.createByController(ViewFactory.java:175)
... 18 more
Caused by: java.lang.NullPointerException
at maxiRename.controller.SideMenuController.init(SideMenuController.java:65)
... 23 more
这是我的sidebarMenuController.java:
package maxiRename.controller;
import javax.annotation.PostConstruct;
import com.jfoenix.controls.JFXListView;
import io.datafx.controller.FXMLController;
import io.datafx.controller.flow.Flow;
import io.datafx.controller.flow.FlowException;
import io.datafx.controller.flow.FlowHandler;
import io.datafx.controller.flow.context.FXMLViewFlowContext;
import io.datafx.controller.flow.context.ViewFlowContext;
import io.datafx.controller.util.VetoException;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
@FXMLController(value = "/maxiRename/view/SideMenu.fxml", title = "Material Design Example")
public class SideMenuController {
@FXML
private StackPane root;
@FXML
private VBox listViewDrawer;
@FXML
private ImageView imageTopDrawer;
@FXML
private JFXListView<?> list1;
@FXML
private Label home;
@FXML
private JFXListView<?> subList;
@FXML
private Label musics;
@FXML
private Label movies;
@FXML
private Label series;
@FXML
private Label help;
@FXML
private Label exit;
@FXMLViewFlowContext
private ViewFlowContext context;
@PostConstruct
public void init() throws FlowException, VetoException {
list1.propagateMouseEventsToParent();
System.out.println(context);
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow");
System.out.println(subList.getItems().get(0));
bindNodeToController(home, HomeController.class, contentFlow, contentFlowHandler);
bindNodeToController(musics, MusicsSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(movies, MoviesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(series, SeriesSettingsController.class, contentFlow, contentFlowHandler);
bindNodeToController(help, HelpController.class, contentFlow, contentFlowHandler);
}
private void bindNodeToController(Node node, Class<?> controllerClass, Flow flow, FlowHandler flowHandler) {
flow.withGlobalLink(node.getId(), controllerClass);
node.setOnMouseClicked((e) -> {
try {
flowHandler.handle(node.getId());
} catch (Exception e1) {
e1.printStackTrace();
}
});
}
}
我的结构文件是否可以帮助您:
我的第一个想法是在错误的路径或类似的路径上,但是如果我更改它,则会收到错误“未设置位置”,因此我想这里的路径很好。
@FXMLController(value = "/maxiRename/view/SideMenu.fxml", title = "Material Design Example")
编辑:maxiRename.controller.SideMenuController.init(SideMenuController.java:65)是:
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
and context is null
最佳答案
好,我找到了!
它是名为“流”的库。在8.0版中可以使用,但在8.1版中不能使用。
从行家我有这个:
<dependency>
<groupId>io.datafx</groupId>
<artifactId>flow</artifactId>
<version>8.1</version>
</dependency>
现在我有这个:
<dependency>
<groupId>io.datafx</groupId>
<artifactId>flow</artifactId>
<version>8.0</version>
</dependency>
谢谢,我希望这对其他人有用;)