Exception in Application constructor Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:893) Caused by: java.lang.RuntimeException: Unable to construct Application instance: class Main at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:750) Caused by: java.lang.NoSuchMethodException: Main.<init>() at java.lang.Class.getConstructor0(Class.java:3110) at java.lang.Class.getConstructor(Class.java:1853) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$7(LauncherImpl.java:818) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294) 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$3(WinApplication.java:177) ... 1 more出现这个报错怎么解决
时间: 2023-10-03 20:02:19 浏览: 108
如何给Ext.panel增加一个背景图片
4星 · 用户满意度95%
这个报错信息是因为在你的Main类中没有默认的构造函数,需要手动添加一个无参构造函数。在Java中,如果没有手动定义构造函数,编译器会自动添加一个无参构造函数,但是一旦你手动定义了一个有参构造函数,编译器就不会自动生成无参构造函数了。
所以你需要在Main类中添加一个无参构造函数,如下所示:
```java
public class Main extends Application {
public Main() {
// 空构造函数
}
// 其他代码...
}
```
这样就可以解决这个报错了。
阅读全文