JavaFX无法使用IntelliJ使用。虽然确实可以编译,但是在尝试启动时出现异常。我在这里发现了类似的问题,但似乎都无法解决我的问题。我得到的异常如下:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:945)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:267)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:255)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:154)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:731)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:418)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
... 5 more
Caused by: java.lang.NoSuchMethodError: <init>
at java.base/java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2614)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2499)
at java.base/java.lang.Runtime.load0(Runtime.java:812)
at java.base/java.lang.System.load(System.java:1821)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:114)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:39)
at javafx.graphics/com.sun.glass.ui.Application.loadNativeLibrary(Application.java:112)
at javafx.graphics/com.sun.glass.ui.Application.loadNativeLibrary(Application.java:120)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$static$2(GtkApplication.java:109)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.<clinit>(GtkApplication.java:108)
at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:146)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
... 10 more
导致此异常所需的代码只有以下内容:
import javafx.application.Application;
import javafx.stage.Stage;
public class Test extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
}
public static void main(String... args)
{
Application.launch(Test.class, args);
}
}
此外,使用Eclipse在旧的Eclipse项目中运行代码的工作正常。但是,如果我将代码复制到IntelliJ,则会收到相同的异常。 我确实在项目设置中使用了Java 9 jdk。
答案 0 :(得分:0)
尝试将Main更改为:
public static void main(String[] args)
{
launch(args);
}
否则,您的问题可能与How to start a new JavaFX project with JDK 9 in IntelliJ
有关