I am writing a java class extending the application class of javafx and am trying to pass an object into the constructor like so:
public class SceneWindow extends Application{
private int x;
private int y;
private int textX;
private int textY;
private static ImagePattern img;
public String title;
private ArrayList<EventHandler<MouseEvent>> events = new ArrayList<EventHandler<MouseEvent>>();
private Text mainDialogue = new Text(0, 0, "test");
private int eventIndex = 0;
public SceneWindow(SceneManager sm){
x = sm.getWindowX();
y = sm.getWindowY();
textX = sm.getTextX();
textY = sm.getTextY();
img = sm.getBackground();
title = sm.getTitle();
events = sm.getEvents();
mainDialogue.setText(sm.getText());
}
I am creating an instance of SceneWindow like this:
SceneWindow sw = new SceneWindow(sm);
with sm
being a SceneManager
object.
However this is not working. I have read elsewhere that this is because you are unable to have a non-zero parameter in a javafx constructor.
This is the error message I am getting:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class application.SceneWindow
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:891)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoSuchMethodException: application.SceneWindow.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3585)
at java.base/java.lang.Class.getConstructor(Class.java:2271)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
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:184)
... 1 more
How can I get around this?