[英]Exception in thread “main” java.lang.RuntimeException: Unable to construct Application instance: class View
I am trying to instantiate an object of type Application
outside of where I wrote my static main method and I am getting this exception. 我试图在我编写静态main方法的地方之外实例化一个
Application
类型的对象,并且遇到了这个异常。
public class Main {
public static void main(String[] args) {
new View(args);
}
}
import javafx.application.Application;
public class View extends Application {
public View(String... args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
}
}
The stack trace: 堆栈跟踪:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class View
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$2/1867083167.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$158(LauncherImpl.java:819)
at com.sun.javafx.application.LauncherImpl$$Lambda$46/1861073381.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1540794519.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$50/1604144171.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/718368050.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/1823101961.run(Unknown Source)
... 1 more
Caused by: java.lang.IllegalStateException: Application launch must not be called more than once
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:162)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:143)
at javafx.application.Application.launch(Application.java:252)
at View.<init>(View.java:33)
... 18 more
Not sure what are you trying to do, but invoking launch(args)
in your constructor looks wrong. 不确定您要做什么,但是在构造函数中调用
launch(args)
似乎是错误的。 From javadocs ( https://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html#launch-java.lang.String...- ): 从javadocs( https://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html#launch-java.lang.String...- ):
The launch method does not return until the application has exited, either via a call to Platform.exit or all of the application windows have been closed.
直到调用退出Platform.exit或关闭了所有应用程序窗口后,启动方法才返回。
Even if it worked, it would hang in your constructor. 即使有效,它也会挂在您的构造函数中。 If you need to do it outside
main()
method, use some static instantiator. 如果需要在
main()
方法之外执行此操作,请使用一些静态实例化器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.