Controlador de la ventana productos, donde inicio la ventana para seleccionar la categoría
Código:
Este es el código para abrir la segunda ventana donde selecciono la categoría@FXML public void openSelectCategory(ActionEvent event) { SelectCategory sc = new SelectCategory(); sc.initSelectCategory(); }
Código:
El controlador de la ventana para seleccionar la categoríaEl código para iniciar la ventana public void initSelectCategory() { try { selectCategoryStage = new Stage(); FXMLLoader selectCategoryLoader = new FXMLLoader(); selectCategoryLoader.setLocation(MainApp.class.getResource("view/SelectCategoryView.fxml")); BorderPane selectCategoryLayout = (BorderPane) selectCategoryLoader.load(); Scene sceneLayot = new Scene(selectCategoryLayout); selectCategoryStage.setScene(sceneLayot); selectCategoryStage.initOwner(MainApp.primaryStage); selectCategoryStage.initModality(Modality.APPLICATION_MODAL); selectCategoryStage.centerOnScreen(); selectCategoryStage.show(); } catch (IOException e) { e.printStackTrace(); } }
Aquí recupero el id de la categoría desde un tableview seleccionada y lo paso a traves de SetUserData y lo ejecuto con la funcion loadCategory
Código:
Controlador de la ventana productos, donde inicio la ventana para seleccionar la categoría @FXML public void selectCategory() { ManageProduct.manageProductStage.setUserData(p); ManageProductViewController m = new ManageProductViewController(); m.loadCategory(); SelectCategory.selectCategoryStage.close(); }
En este código recupero el valor del ID, se muestra el valor recuperado perfectamente en un JOpcionPane, el problema es cuando se lo asigno a tfShowCategoryProduct ( textfield con SetText) me lanza un error, incluso cuando le asigno cualquier texto al textfiel manualmente, me da el mismo error, he puesto el textfiel como static y tampoco funciona.
Código:
public void loadCategory() { String data = ManageProduct.manageProductStage.getUserData().toString(); if (data != null) { tfShowCategoryProduct.setText(data); JOptionPane.showMessageDialog(null, data); } else { JOptionPane.showMessageDialog(null, "Error"); } }
Este es el error
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknow n Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandle r.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatc hBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchB ubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchB ubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.disp atchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unkno wn Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavi or.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase $1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase $1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalE ventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatc hBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchB ubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchB ubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.disp atchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatch Event(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispat chEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unkno wn 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(Unknow n Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Un known Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$Mo useEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$Mo useEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.la mbda$handleMouseEvent$354(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithou tRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.ha ndleMouseEvent(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(Nativ e Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$14 8(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 49 more
Caused by: java.lang.NullPointerException
at com.maurifuentes.bm.view.ManageProductViewControll er.loadCategory(ManageProductViewController.java:3 07)
at com.maurifuentes.bm.view.SelectCategoryViewControl ler.selectCategory(SelectCategoryViewController.ja va:129)
... 58 more