There are 2 *. FXML
file, each of which is connected to your *. java
file. In one.fxml
Yes imageview
FX: id = "image"
How from twocontroller.java
Place the image in imageview
file one.fxml
. It seems to me that the code below may well come out only you need to get imageview
with one.fxml
stackpane sp = new stackpane ();
Image img = new image ("javafx.jpg");
Imageview imgview = new imageview (img);
sp.getchildren (). Add (imgView);
In general, I can not understand why I get nullpointerexception
Here is the code Two.java
one con;
Image img = new image (getClass (). GetResource ("logo.png"). ToexternalForm ());
ImageView image = new imageview (img);
con .Anchorpane.getchildren (). Add (image);
and if it is written in one.java
That everything works without errors.
Inheritance is not suitable, error crashes:
exception in application start method & lt; br & gt; exception in thread "main" java.lang.runtimeException: Exception in Application Start Method
at com.sun.javafx.application.launcherimpl.LaunChapplication1 (Launcherimpl.java:917)
at com.sun.javafx.application.launcherimpl.Lambda $ Launchapplication $ 155 (Launcherimpl.java:18)
at java.lang.Thread.Run (Thread.java:745)
CauseD by: java.lang.outofmemorryRor: Java Heap Space
at java.nio.heapbytebuffer. & lt; Init & gt; (HeapByTebuffer.java:7)
at java.nio.bytebuffer.allocate (bytebuffer.java:335)
at com.sun.javafx.iio.png.pngimageloader2.load (pngimageloader2.java:652)
at com.sun.javafx.iio.imagestorage.Loadall (Imagestorage.java :64)
at com.sun.javafx.iio.imagestorage.Loadall (Imagestorage.java: 26)
at com.sun.javafx.tk.quantum.prismimageloader2.loadall (prismimialoader2.java:127)
at com.sun.javafx.tk.quantum.prismimageloader2. & lt; Init & gt; (prismimageloader2.java:71)
at com.sun.javafx.tk.quantum.quantumtoolkit.loadimage (quantumtoolkit.java:720)
at javafx.scene.image.Inage.loadimage (image.java:1065)
at javafx.scene.image.image.initialize (image.java:807)
at javafx.scene.image.image. & lt; Init & gt; (image.java:695)
at com.sun.javafx.fxml.builder.javafximagebuilder.build (javafximagebuilder.java:47)
at com.sun.javafx.fxml.builder.javafximagebuilder.build (javafximagebuilder.java:37)
at javafx.fxml.fxmlloader $ valueelement.processendelement (fxmlloader.java:763)
at javafx.fxml.fxmlloader.processendelement (fxmlloader.java:2823)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:2532)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:2441)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:3214)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:3175)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java :148)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java: 124)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java :104)
at javafx.fxml.fxmlloader.load (fxmlloader.java:3097)
at sample.generalcontroller.inityalize (generalcontroller.java:43)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:2548)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:2441)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:3214)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java:3175)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java :148)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java: 124)
at javafx.fxml.fxmlloader.loadimpl (fxmlloader.java :104)
at javafx.fxml.fxmlloader.load (fxmlloader.java:3097)
Here ImageView
from one.java
@fxml
Public ImageView Image;
There are assumptions that the wrong image
add, although I tried to change the name, the same result.
Caused by: java.lang.nullPointerexception
at sample.Menucontroller.onclickscaner (Menucontroller.java:46)
... 62 more
Also, in addition to NPE, there is still such a
exception in thread "javafx application thread" java.lang.RuntimeException: java.lang.reflect.invocationTargeTexception
at javafx.fxml.fxmlloader $ MethodHandler.Invoke (fxmlloader.java:1774)
at javafx.fxml.fxmlloader $ ControllermethodeventHandler.Handle (fxmlloader.java:1657)
at com.sun.javafx.event.compositeEventHandler.dispatchBubblingevent (compositeeventhandler.java:86)
at com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (EventHandlermanager.java:238)
at com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (EventHandlermanager.java:191)
at com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent (compositeeventdispatcher.java:9)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:8)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.eventutil.fireEventImpl (Eventutil.java:74)
at com.sun.javafx.event.eventutil.fireEvent (Eventutil.java:49)
at javafx.event.event.fireEvent (event.java:198)
at javafx.scene.node.fireEvent (node.java:8413)
at javafx.scene.control.button.fire (Button.java:185)
at com.sun.javafx.scene.control.behavior.buttonbehavior.mousereleased (buttonbehavior.java:18)
at com.sun.javafx.scene.control.skin.behaviorskinbase $ 1.Handle (behaviorskinbase.java:96)
at com.sun.javafx.scene.control.skin.Behaviorskinbase $ 1.Handle (Behaviorskinbase.java:89)
at com.sun.javafx.event.compositeEventHandler $ NormaleventHandlerRecord.Hlandlebublingevent (compositeeventhandler.java:21)
at com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent (compositeeventhandler.java:80)
at com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (EventHandlermanager.java:238)
at com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent (EventHandlermanager.java:191)
at com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent (compositeeventdispatcher.java:9)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:8)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.basiceventdispatcher.dispatchevent (BasiceventDispatcher.java:6)
at com.sun.javafx.event.eventdispatchchainimpl.dispatchevent (eventdispatchchainimpl.java:11)
at com.sun.javafx.event.eventutil.fireEventImpl (Eventutil.java:74)
at com.sun.javafx.event.eventutil.fireEvent (Eventutil.java ::4)
at javafx.event.event.fireEvent (event.java:198)
at javafx.scene.scene $ mousehandler.process (Scene.java :757)
at javafx.scene.scene $ mousehandler.access $ 1500 (Scene.java :485)
at javafx.scene.scene.impl_processmouseEvent (Scene.java:1762)
at javafx.scene.scene $ scenepeerlistener.mouseevent (Scene.java:2494)
at com.sun.javafx.tk.quantum.glassvieweventHandler $ MouseEventNotification.Run (GlassVieweventHandler.java: 20)
at com.sun.javafx.tk.quantum.glassVieweventHandler $ MouseEventNotification.Run (GlassVieweventHandler.java:29)
at java.security.accesscontroller.doprivileged (Native Method)
at com.sun.javafx.tk.quantum.glassvieweventHandler.Lambda $ handlemouseevent $ 354 (GlassVieweventHandler.java:416)
at com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock (quantumtoolkit.java:389)
at com.sun.javafx.tk.quantum.glassvieweventHandler.HandleMouseEvent (GlassVieweventHandler.java: 05)
at com.sun.glass.ui.view.handlemouseevent (view.java:55)
at com.sun.glass.ui.view.notifymouse (view.java:937)
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: java.lang.reflect.invocationTargeTexception
AT Sun.Reflect.nativeMethodAccessorImpl.Invoke0 (Native Method)
AT Sun.Reflect.nativeMethodAccessorImpl.Invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.delegationmethodaccessorimpl.invoke (delegationmethodaccessorimpl.java:43)
at java.lang.reflect.method.invoke (Method.java:498)
AT Sun.Reflect.misc.trampoline.invoke (methodutil.java:71)
AT Sun.Reflect.GeneratedMethodAccessor1.invoke (Unknown Source)
at sun.reflect.delegationmethodaccessorimpl.invoke (delegationmethodaccessorimpl.java:43)
at java.lang.reflect.method.invoke (Method.java:498)
at sun.reflect.misc.methodutil.invoke (methodutil.java:27)
at javafx.fxml.fxmlloader $ MethodHandler.invoke (fxmlloader.java:1771)
... 52 more
Help Me Please …
Answer 1, Authority 100%
Well, it may be not the best option from possible, but it works exactly because I need.
onecontroller.java
@ fxml
Public Static ImageView Image;
@Fxml
Public Anchorpane Anchorpane;
@Fxml
Public Void Initialize (URL URL, ResourceBundle Br) {
click ();
}
void click () {
TWOCONTROLLER CONTR = NEW TWOCONTROLLER ();
image = new image ();
If (image! = NULL) {
Image i = null;
Image IM = CONTR.Setimage (I);
image.setimage (CONTR.Setimage (IM));
Anchorpane.Getchildren (). Add (image);
}
}
twocontroller.java
....
Public Image Setimage (image img) {
Image img = null;
i = img;
i = new image (getClass (). GetResource ("logo.png")));
Return img;
}