我有一个JavaFX程序,创建了简单的GUI。但是每当我运行它时,它会给我一个似乎无法修复的错误。
以下是代码:
package me.sam.algorithm;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
class SchoolDay extends Application {
public void start(Stage Primarystage) {
//main menu
VBox menu = new VBox();
HBox mini1= new HBox();
HBox mini2= new HBox();
menu.setPadding(new Insets(15,12,15,12));
menu.setSpacing(20);
mini1.setSpacing(3);
mini2.setSpacing(3);
Scene mainm = new Scene(menu, 500, 500, Color.BLACK);
Label s1 = new Label("What day is it?");
Label s2 = new Label("Is it late or regular start?");
Label s3 = new Label("If you've filled everything out, press start!");
Button beg = new Button("Start!");
ToggleButton l1 = new ToggleButton("Regular Start");
ToggleButton l2 = new ToggleButton("Late Start");
ToggleButton d1 = new ToggleButton("Day 1");
ToggleButton d2 = new ToggleButton("Day 2");
ToggleButton d3 = new ToggleButton("Day 3");
ToggleButton d4 = new ToggleButton("Day 4");
ToggleButton d5 = new ToggleButton("Day 5");
ToggleButton d6 = new ToggleButton("Day 6");
ToggleGroup togg1 = new ToggleGroup();
ToggleGroup togg2 = new ToggleGroup();
d1.setToggleGroup(togg1);
d2.setToggleGroup(togg1);
d3.setToggleGroup(togg1);
d4.setToggleGroup(togg1);
d5.setToggleGroup(togg1);
d6.setToggleGroup(togg1);
l1.setToggleGroup(togg2);
l2.setToggleGroup(togg2);
mini2.getChildren().addAll(l1,l2);
mini1.getChildren().addAll(d1,d2,d3,d4,d5,d6);
menu.getChildren().addAll(s1,mini1,s2,mini2,s3,beg);
menu.setAlignment(Pos.BASELINE_CENTER);
mini1.setAlignment(Pos.CENTER);
mini2.setAlignment(Pos.CENTER);
Primarystage.setTitle("MICDS Day");
Primarystage.setScene(mainm);
Primarystage.show();
//main scene
}
public static void main(String[] args) {
launch(args);
}
}}
`
我在这里发帖的原因是,在我开始从jfxrt.jar中提取modena.css文件之前,此错误并不存在。我在JDK / JRE中搞砸了什么,或者是代码错误。还有,它甚至可以修复吗?我已经尝试卸载jdk并重新安装它。为了防止它重要,我使用eclipse neon IDE。
无论我做什么,以下是它给我的错误:
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Unable to construct Application i instance: class me.samJFX.SchoolDay
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: me.samJFX.SchoolDay.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:818)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
答案 0 :(得分:1)
制作SchoolDay
班public
。 Application.launch
无法访问导致此异常的非public
类的构造函数
java.lang.NoSuchMethodException: me.samJFX.SchoolDay.<init>()
同时修复软件包(me.samJFX
!= me.sam.algorithm
)。
此外,编译器会抱怨上一个}
,因为该类已被前一个}
关闭。
(我不知道你怎么能在最后两期中运行这段代码。)