JavaFX does not work with IntelliJ (jdk 9)

≯℡__Kan透↙ 提交于 2021-02-08 08:12:50

问题


JavaFX is not working for me using IntelliJ. While it does compile, I get an Exception when trying to launch. I've found similar issues here, none of which seemed to hold an answer to my problem. The Exception I get is the following:

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

The code required to cause this Exception is only the following:

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);
    }
}

Furthermore, running code form old Eclipse projects using Eclipse is working. However, if I copy the code over to IntelliJ, I get the same Exception. I do use the java 9 jdk in the project settings.


回答1:


Try changing your Main to:

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

Otherwise your problem might be related to How to start a new JavaFX project with JDK 9 in IntelliJ



来源:https://stackoverflow.com/questions/51113343/javafx-does-not-work-with-intellij-jdk-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!