如何在Java 8 Ubuntu上启动JavaFX应用程序?
发布时间:2020-12-15 02:19:43 所属栏目:Java 来源:网络整理
导读:我试图启动应用程序,但有错误: 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.Cla
我试图启动应用程序,但有错误:
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 并且消息无法在堆栈跟踪结束时加载Glass工厂类. 我还尝试将javafx添加为maven依赖项,并将此jar添加到classpath中.我将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(); } } 更新1: 我使用debug并在第1057行发现了ThreadPoolExecutor.java中的excpetion抛出.另外: 是的!执行此代码片段后,第一个异常出现在项目控制台中. 解决方法
您需要下载并安装openjfx lib.
sudo apt install openjfx应该可以解决问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |