但是最后一个选项也没有帮助,因为我仍然总是得到相同的错误:空指针异常。它来自模型生成密码的行,所获得的字符串绑定到seconde视图的控制器中的一个值。
我有点困在这里,我想混合两种不同的方法来编码我的视图不是最好的方法。尽管如此,也许我没有正确地进行绑定,这是我最想和最希望的。
因此,我的第一个视图的控制器如下所示(生成密码):
public class GeneratePasswordController implements EventHandler<MouseEvent>{
@FXML private displayPasswordController displayPasswordController;
@Override
public void handle(MouseEvent event) {
//Doing some stuff that works, then generating the password and null pointer exception occurs here
//The method getNewPassword() returns a String (the password).
//The model is accessed statically (an instance has been created in the Application file (Main.java)).
displayPasswordController.pwdValueProperty().bind(Bindings.createStringBinding(()
-> Main.myModel.getNewPassword()));
}
}
public class NewPswdController {
@FXML private TextField displayPassword;
private final StringProperty pwdValue = new SimpleStringProperty("Password");
public StringProperty pwdValueProperty() {
return pwdValue;
}
public String getPwdValue() {
return pwdValue.get();
}
public void setPwdValue(String value) {
this.pwdValue.set(value);
}
@FXML
void initialize() {
dispPassword.textProperty().bind(Bindings.format("%s", pwdValue));
}
}
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at s03.GeneratePasswordController.handle(GeneratePasswordController.java:61)
at s03.GeneratePasswordController.handle(GeneratePasswordController.java:1)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$271/1952832519.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1232367853.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
故障来自显示密码的控制器。null指针很可能来自这样一个事实,即没有该控制器的实例。
错误的地方在于我包含了使用@fxml注释显示密码的控制器。
在生成密码的控制器中,下面的代码可以正常工作:
try {
//Load the view and controller
FXMLLoader loader = new FXMLLoader(getClass().getResource("displayPassword.fxml"));
Parent displayPassword = (Parent)loader.load();
Scene displayPasswordScene = new Scene(displayPassword);
displayPasswordController controller = loader.getController();
//Generate the password and set it
controller.setPwdValue(Pastis.model.getNewPassword());
//Load the new view on the stage
Main.getStage().setScene(displayPasswordScene);
Main.getStage().show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我将StackPane作为根,并在主应用程序Start()方法中加载了BorderPane布局。在BorderPane布局中,我有两个按钮:一个用于添加fxml文件(Menu.fxml),另一个用于删除此文件。一旦菜单。fxml已加载,菜单中有一个按钮。fxml,单击时应在先前加载的BorderPane布局的中心加载一个fxml文件(One.fxml)。然而,在这个阶段,我得到了一个空指针异常。你
问题内容: 我打算学习来自许多不同的MV *框架的AngularJS。我喜欢框架,但是在控制器之间传递数据时遇到了麻烦。 假设我有一个带有一些输入(input.html)的屏幕和一个控制器,比方说InputCtrl。 此视图上有一个按钮,可将您带到另一个屏幕,例如,使用控制器ApproveCtrl批准(approve.html)。 此ApproveCtrl需要来自InputCtrl的数据。在较大的
以下是在sun.reflect.nativeMethodAccessorImpl.Invoke0(本机方法)在sun.reflect.nativeMethodAccessorImpl.Invoke(未知源)在sun.reflect.NativeMethodAccessorImpl.Invoke(未知源)在java.lang.Reflect.Method.Invoke(未知源)在com.codena
问题内容: 我想单击一列并将单元格索引发送到新阶段。但是我无法将参数()传递给另一个控制器。我已经尝试了所有方法,但仍然无法正常工作。 主控制器 EditClientController 问题答案: 如果要在FXML文件中指定控制器(因此您不能使用Deepak的答案), 并且 要访问方法中的索引(因此您不能使用José的答案),则可以使用控制器工厂:
我对沉香酒很陌生...有人能告诉如何在thymeleaf html和spring控制器之间传递值吗...请为Thymeleaf-Spring-MVC提供好的教程... @requestmapping(value=“/owners”,method=requestmethod.get)公共字符串processFindForm(Owner Owner,BindingResult result,Model
我很难将参数从一个控制器传递到另一个控制器。 具体来说: LoginController向MainController传递。 null LoginController.java MainController.java