我正在尝试启动应用程序但出现错误:
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
在堆栈跟踪的末尾有一条消息Failed to load Glass factory class
。
我还尝试将 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();
}
}
更新 1:
我使用调试并发现异常抛出在 ThreadPoolExecutor.java 的第 1057 行。另外:
是的!执行此代码片段后,项目控制台中出现第一个异常。
最佳答案
您需要下载并安装 openjfx 库。
sudo apt install openjfx
应该可以解决问题。
关于java - 今天如何在 Java 8 Ubuntu 上启动 JavaFX 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44804394/