gpt4 book ai didi

java - 为什么我在 io.datafx 中遇到 java.lang.NullPointerException?

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:32 26 4
gpt4 key购买 nike

我发现了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();
}
});
}
}

我的结构文件如果可以帮助你: Structure project

我的第一个想法是一条错误的路径或类似的东西,但如果我更改它,我会收到错误“未设置位置”,所以我想我这里的路径很好。

@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

最佳答案

好的,我找到了!

这是名为“flow”的库。在 8.0 版本中它可以工作,但在 8.1 版本中不行。

从 Maven 中我得到了这个:

<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>

谢谢,我希望这对其他人有用;)

关于java - 为什么我在 io.datafx 中遇到 java.lang.NullPointerException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39745563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com