我试图启动应用程序,但遇到错误:
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添加到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。另外:
是的!执行此代码片段后,第一个异常出现在项目控制台中。
答案 0 :(得分:0)
您需要下载并安装openjfx lib。
sudo apt install openjfx
应该可以解决问题。
答案 1 :(得分:0)
好的,我明白了。
首先我的jdk坏了,所以我下载了新的。
即使您在“项目”标签中更改了sdk,也可以在IDEA中忘记更改“模块”部分中的项目sdk。