JavaFX不适用于IntelliJ(jdk 9) [英] JavaFX does not work with IntelliJ (jdk 9)

查看:129
本文介绍了JavaFX不适用于IntelliJ(jdk 9)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX无法使用IntelliJ使用.虽然确实可以编译,但是在尝试启动时会出现异常.我在这里发现了类似的问题,但似乎都无法解决我的问题.我得到的异常如下:

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

此外,使用Eclipse在旧的Eclipse项目中运行代码的工作正常.但是,如果我将代码复制到IntelliJ,则会收到相同的Exception. 我确实在项目设置中使用了Java 9 jdk.

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.

推荐答案

尝试将Main更改为:

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

这篇关于JavaFX不适用于IntelliJ(jdk 9)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆