Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
今天如何在Java8Ubuntu上启动JavaFX应用程序?_Java_Javafx_Javafx 8 - Fatal编程技术网

今天如何在Java8Ubuntu上启动JavaFX应用程序?

今天如何在Java8Ubuntu上启动JavaFX应用程序?,java,javafx,javafx-8,Java,Javafx,Javafx 8,我正在尝试启动应用程序,但出现错误: java.lang.ClassNotFoundException: com.sun.glass.ui.gtk.GtkPlatformFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.lo

我正在尝试启动应用程序,但出现错误:

java.lang.ClassNotFoundException: com.sun.glass.ui.gtk.GtkPlatformFactory   at
  java.net.URLClassLoader.findClass(URLClassLoader.java:381)  at
  java.lang.ClassLoader.loadClass(ClassLoader.java:424)   at
  java.lang.ClassLoader.loadClass(ClassLoader.java:357)   at
  java.lang.Class.forName0(Native Method)   at
  java.lang.Class.forName(Class.java:264)   at
  com.sun.glass.ui.PlatformFactory.getPlatformFactory(PlatformFactory.java:42)
    at com.sun.glass.ui.Application.run(Application.java:146)   at
  com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
    at
  com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
    at
  com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
    at
  com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:337)
    at
  com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    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:767)
  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:767)
  Caused by: java.lang.NullPointerException   at
  com.sun.glass.ui.Application.run(Application.java:146)  at
  com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
    at
  com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
    at
  com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
    at
  com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:337)
    at
  com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    ... 5 more 
堆栈跟踪结束时,出现一条消息
未能加载玻璃工厂类

我还尝试将javafx添加为maven依赖项,并将这个jar添加到类路径中。我在我的项目中使用IDEA

更新

我的代码是简单的Hello JavaFX exmaple:

public class Application extends javafx.application.Application {

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

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
公共类应用程序扩展了javafx.Application.Application{
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公共无效开始(阶段primaryStage){
按钮btn=新按钮();
btn.setText(“说‘你好,世界’”);
btn.setOnAction(新的EventHandler


是的!执行此代码片段后,第一个异常出现在项目控制台中。

您需要下载并安装openjfx库

sudo-apt-install-openjfx
应该可以做到这一点。

好的,我知道了

首先我的jdk坏了,所以我下载了一个新的


此外,在IDEA中,即使您在“项目”选项卡中更改了sdk,也不要忘记在“模块”部分更改项目sdk。

您需要共享您的代码。您有一个NullPointerException。您的java版本是什么?@SergeyGrinev我在我的项目中使用java 8(opend jdk)
java-version
说了什么?你的代码运行得很好。它确实显示了一个带有按钮的窗口。如果你看顶部,上面写着ClassNotFoundException,那么你肯定错过了某个类。我希望你的java安装完好无损。你能把你的类从应用程序重命名为其他类吗,因为有时你可能会进入另一个类itance问题。你安装了GTK吗?我已经检查过了,是的,我有2.24.30和3.18.9两个版本。你试过Oracle JRE吗?我在17.04,使用Oracle JRE,工作正常。@m.leRutte是的,我试过7和8 Oracle和openjdk 8