java - JavaFX Parameter passing -
this question has answer here:
- passing parameters javafx fxml 6 answers
i've been endlessly struggling code, i'm trying send values of 2 strings "window" perform function on them keep getting sorts of errors.
i've thoroughly read dependancy injection thread , main problem (pane) cast in 10th line.
also, i've read this 1 well , answer , code plain chaotic.
what trying this:
i have lets main document , i'm trying send 1 of values child:
my code maincontroller:
@fxml void initialize() throws malformedurlexception { parametersender.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent event) { parent root; try { root = fxmlloader.load(getclass().getclassloader().getresource("filetree/childwindow.fxml"),resources); stage stage = new stage(); stage.settitle("child"); stage.setscene(new scene(root, 500, 500)); fxmlloader loader = fxmlloader(getclass().getclassloader().getresource("filetree/childwindow.fxml"), resources); //i fixed this, thank much, uchiha itachi childwindowcontroller controller = loader.<childwindowcontroller>getcontroller(); controller.firstparameter = getfirstfield(); //this getter of firsttextareafield controller.secondparameter = getsecondfield();//this getter of secondtextareafield stage.show(); } catch (ioexception e) { e.printstacktrace(); }//end of catch }//end of initialize
and childcontroller:
@fxml void testacquiredparametersfromparent(mouseevent event) { system.out.println(firstparameter + " " + secondparameter); }
when run code exception on runtime:
java.lang.classcastexception: javafx.scene.layout.anchorpane cannot cast javafx.fxml.fxmlloader @ filetree.fxmldocumentcontroller$5.handle(fxmldocumentcontroller.java:17) @ filetree.fxmldocumentcontroller$5.handle(fxmldocumentcontroller.java:3) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:69) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:69) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:217) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:170) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:38) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:37) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:53) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:28) @ javafx.event.event.fireevent(event.java:171) @ javafx.scene.node.fireevent(node.java:6867) @ javafx.scene.control.button.fire(button.java:179) @ com.sun.javafx.scene.control.behavior.buttonbehavior.mousereleased(buttonbehavior.java:193) @ com.sun.javafx.scene.control.skin.skinbase$4.handle(skinbase.java:336) @ com.sun.javafx.scene.control.skin.skinbase$4.handle(skinbase.java:329) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:64) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:217) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:170) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:38) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:37) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:35) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:92) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:53) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:33) @ javafx.event.event.fireevent(event.java:171) @ javafx.scene.scene$mousehandler.process(scene.java:3311) @ javafx.scene.scene$mousehandler.process(scene.java:3151) @ javafx.scene.scene$mousehandler.access$1900(scene.java:3106) @ javafx.scene.scene.impl_processmouseevent(scene.java:1563) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2248) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:250) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:173) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:292) @ com.sun.glass.ui.view.handlemouseevent(view.java:530) @ com.sun.glass.ui.view.notifymouse(view.java:924) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.access$100(winapplication.java:17) @ com.sun.glass.ui.win.winapplication$3$1.run(winapplication.java:67) @ java.lang.thread.run(thread.java:744)
any appreciated.
thank in advance.
edit\ fixed loader. again, uchiha itachi.
your error because of below line
fxmlloader loader = fxmlloader.load(getclass().getclassloader(). getresource("filetree/childwindow.fxml"), resources);
here, trying create fxmlloader reference, instead have used load()
of fxmlloader
.
fxmlloader's load()
load pane used root in fxml. so, instead of using
fxmlloader.load()
you must directly use
fxmlloader fxmlloader = new fxmlloader(getclass().getclassloader(). getresource("filetree/childwindow.fxml"), resources);
Comments
Post a Comment