IntelliJ doesn't recognize JavaFX imports

Answered

I've got JavaFX in my Gradle dependencies/got the plugin, it shows all the JavaFX's JAR files under external libraries and it just doesn't work. It just gives me an error "package javafx.fxml does not exist". I have tried checking that my Java version is correct, project bytecode version, JavaFX plugin installed, JavaFX installed and i even added the JAR-s manually but nothing works.  I also tried reinstalling IntelliJ.

0
7 comments
Avatar
Permanently deleted user

That did not work.

0

When do you get the error, in the editor or when compiling?

Please share a sample project to reproduce the issue: https://uploads.jetbrains.com.

Make sure the project is set up according to https://www.jetbrains.com/help/idea/javafx.html.

See also https://openjfx.io/openjfx-docs/ .

0
Avatar
Permanently deleted user

2021_03_15_WYSi5mnUdcVK3hZL

Both, in the editor and when compiling. 

0

The issue is with your project, not with IntelliJ IDEA.

First problem is that the import statement is incorrect:

import javafx.fxml;

Should be changed to this:

import javafx.fxml.*;

The second problem is that you do not specify JavaFX modules to be used in the module dependencies.

cScripts\scripts\cChompy\build.gradle.kts needs to be updated with something like this:

javafx {
modules = listOf("javafx.controls", "javafx.fxml", "javafx.web")
version = "15.0.1"
}
0
Avatar
Permanently deleted user

Thank you so much! 

javafx {
modules = listOf("javafx.controls", "javafx.fxml", "javafx.web")
version = "15.0.1"
}


This piece of code fixed it.

0

It's documented here: https://openjfx.io/openjfx-docs/#gradle . Please always follow the official documentation before asking questions.

0

Please sign in to leave a comment.