JavaFX does not work with IntelliJ (jdk 9)


JavaFX does not work with IntelliJ (jdk 9)



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.





Works fine on my machine. What IDE version do you use?
– y.bedrov
yesterday





@y.bedrov Pastebin link because StackOverflow appearently doesn't support multiline in replies: pastebin.com/qTkUV6cy
– AlmostSmart
yesterday




1 Answer
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





Changing the main makes no difference. I think the linked thread might be related to the fact that jdk 9 was not yet released at this date. In do have java 9 selected for the Project language level. Inerestingly enough, it does work if I set both the Project SDK and the Project Language Level to java 8. Other projects that do not involve JavaFX do work properly using Java 9, though.
– AlmostSmart
Jun 30 at 10:49







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Extract Id from Twitch Clip URL

Why are these constructs (using ++) undefined behavior in C?

I'm Still Waiting (Diana Ross song)