无法构建 javafx.application.Application 实例 [英] Unable to construct javafx.application.Application instance

查看:38
本文介绍了无法构建 javafx.application.Application 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试来自 Oracle 站点的 JavaFX 教程 [fxml 教程] (http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm).

I'm trying a JavaFX tutorial from the Oracle site [fxml tutorial] (http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm).

package fxml;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

class Main extends Application {

    public Main() {}

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("welcome.fxml"));

        Scene scene = new Scene(root);

        stage.setTitle("FXML UI");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String args[]) {
        launch(args);
    }

}

这是我不断遇到的例外情况.该应用程序未显示在屏幕上.我从另一个堆栈溢出答案中做了非参数 Main() 构造函数,但它没有修复它.

And this is the exception that I'm continuously getting. The application doesn't show up on the screen. I did the non-args Main() constructor from another stack overflow answer but it didn't fix it.

Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fxml.Main
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:884)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalAccessException: Class com.sun.javafx.application.LauncherImpl$7 can not access a member of class fxml.Main with modifiers "public"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:295)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:287)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:398)
    at com.sun.javafx.application.LauncherImpl$7.run(LauncherImpl.java:791)
    at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

推荐答案

class Main extends Application 缺少初始的 public 关键字.

class Main extends Application is missing the initial public keyword.

还有 public Main() {} 是不必要的.

这篇关于无法构建 javafx.application.Application 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆