我的问题是我传递给新创建的窗口的NOT NULL参数为NULL。我读过很多关于如何通过setter将参数传递到另一个窗口的帖子,对我来说似乎一切都很好,但它并不起作用。
public void loginPerson(ActionEvent e) {
try {
Person p = look_up.accessUser(loginTabEmail.getText(), loginTabPassword.getText()); // ITS NOT NULLL
if (p == null) {
System.out.println("loginPerson: Bad login");
} else {
System.out.println("User logged in! " + loginTabEmail.getText() + " " + loginTabPassword.getText());
loginTabEmail.clear();
loginTabPassword.clear();
FXMLLoader loader = new FXMLLoader(getClass().getResource("userMenu.fxml"));
SplitPane newWindow = (SplitPane) loader.load();
userMenuController controller = loader.getController();
controller.setMainMenu(this);
controller.setMyUser(p); // trying to pass Person to another controller
Stage stage = new Stage();
stage.initModality(Modality.WINDOW_MODAL);
stage.initOwner(registerTabSignUp.getScene().getWindow());
stage.setTitle("MyLibrary");
Scene scene = new Scene(newWindow);
stage.setScene(scene);
stage.show();
}
} catch (Exception i) {
System.err.println("Client exception: " + e.toString());
i.printStackTrace();
}
}
public class userMenuController implements Initializable {
private mainMenuController mainMenu;
private Person myUser;
private static RMIInterface look_up;
private ObservableList<Book> userBooksObservableList = FXCollections.observableArrayList();
private ObservableList<Book> libraryObservableList = FXCollections.observableArrayList();
@FXML
private ListView<Book> myBooksSection;
@FXML
private ListView<Book> libraryBooksSection;
public userMenuController() throws Exception {
look_up = (RMIInterface) Naming.lookup("//localhost/MyServer");
}
public void showMyBooks() {
myBooksSection.setItems(userBooksObservableList);
userBooksObservableList.addAll(myUser.getPersonBooks()); // myUser is NULL ?? why ??
userBooksObservableList.add(new Book("sadas"));
}
public void showLibraryBooks() throws MalformedURLException, RemoteException, NotBoundException {
libraryBooksSection.setItems(libraryObservableList);
libraryObservableList.addAll(look_up.getAvailableBooks());
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
try {
showMyBooks();
showLibraryBooks();
} catch (Exception e) {
e.printStackTrace();
}
}
public void setMainMenu(mainMenuController ctrl) {
mainMenu = ctrl;
}
public void setMyUser(Person p) {
myUser = p;
}
}
正如调试器所说,MyUser
以及MainMenu
似乎为空。错误消息:
java.lang.NullPointerException
at mainMenu.userMenuController.showMyBooks(userMenuController.java:46)
at mainMenu.userMenuController.initialize(userMenuController.java:61)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
at mainMenu.mainMenuController.loginPerson(mainMenuController.java:66)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1782)
at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8890)
at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3862)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2590)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:411)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:835)
您可以从堆栈跟踪中看到,崩溃发生在MainMenu.UserMenuController.ShowMyBooks()
方法上(第一个位于xxx
行),该方法由MainMenu.UserMenuController.Initialize()
调用(第二个位于xxx
行)。
因为JavaFX在获取controller对象之前调用initialize()
方法,所以这个p
成员变量显然当时没有初始化,这意味着它是一个null指针(成员变量初始化为null,表示Java)。
有关调用序列的更多详细信息,请参阅此问题。
顺便说一下,通常建议类的第一个字符使用大写。
所以,我需要将参数(ID)传递给通过单击TableView打开的新窗口。具体来说,我需要将series Id参数从MainController传递到TvShowsAboutController。 我正在从MainController打开TvShowsAboutController。像这样: 但是我不知道如何在TvShowsAvoutController类中传递参数。如果我创建新的TvShowsAb
问题内容: 如何将参数传递给javafx中的辅助窗口?有没有办法与相应的控制器通信? 例如:用户从中选择一个客户,TableView然后会打开一个新窗口,显示该客户的信息。 newStage将是新窗口。问题是,我找不到告诉控制器在哪里寻找客户信息的方法(通过将id作为参数传递)。 有任何想法吗? 问题答案: 推荐方法 该答案列举了将参数传递给FXML控制器的不同机制。 对于小型应用程序,我强烈建议
如何在JavaFX中将参数传递给辅助窗口?有没有办法与相应的控制器进行通信? 例如:用户从中选择一个客户,然后打开一个新窗口,显示该客户的信息。 将是新窗口。问题是,我找不到一种方法告诉控制器在哪里寻找客户的信息(通过将id作为参数传递)。 有什么想法吗?
查看这段代码,它们展示了一种在登录后显示新窗口的方法。当用户名和密码是正确的,它打开新的对话框。我想要一个按钮点击打开新的对话框,而不检查用户名和密码。
我目前正在尝试将我的Firebase数据库中的内容读入中,但我希望将它们从最后一个节点加载到第一个节点。所以我决定将键放入一个数组中,然后尝试从数组的末尾读到前面,但是当我尝试访问键数组时,我看到的是中的参数'path string'传递null错误。
本文向大家介绍javascript实现浏览器窗口传递参数的方法,包括了javascript实现浏览器窗口传递参数的方法的使用技巧和注意事项,需要的朋友参考一下 a.html b.html