LauCirco
LauCirco

Reputation: 331

Error:(3, 26) java: package javafx.application does not exist

I have a new pc, I have installed inteliJ with JDK and JRE 9.0.1. I also installed SceneBuilder 9.0.1. I have copied the project that I had on old pc and when I run it I get this error: Error:(3, 26) java: package javafx.application does not exist. Do I need to install something else that contains this package? Thank you.

Upvotes: 33

Views: 147741

Answers (8)

tomorrow
tomorrow

Reputation: 1378

If this happens to you in a modular project with JavaFx version 17 using Maven, just try the usual things like standing on your head, walking on the ceiling, rotating the Earth in the opposite direction or even reading https://openjfx.io/openjfx-docs/ and then just switch to the version 17.0.1 or later and it should work:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>17.0.1</version>
</dependency>

Upvotes: 11

invzbl3
invzbl3

Reputation: 6440

I've reproduced the same issue after adding the library, but using Java 11 & JavaFX 11.

To fix it, I've followed such steps:

  1. Firstly, click Project Structure -> Libraries and check if library isn't used:

enter image description here

  1. Secondly, open Project Structure -> Problems and click [Fix] -> Add to Dependencies...:

enter image description here

  1. Thirdly, choose as module and click OK:

enter image description here

  1. Lastly, click Apply and OK.

As result, will be:

enter image description here

Upvotes: 0

Nicholas Edwards
Nicholas Edwards

Reputation: 1

My problem was that I deleted my SDK 15 and installed SDK 16. Check your Libraries locations under File -> Project Structure -> Libraries. If your library version is lower than what you have selected under Project Settings -> Project -> Project SDK. You are going to have a bad time.

Upvotes: 0

Nikolaj Hansen
Nikolaj Hansen

Reputation: 255

If you are java 8+ the javafx libs are not included. you need to add them via your favorite build tool as a compile runtime lib.

Upvotes: 2

Himel Rana
Himel Rana

Reputation: 666

Be careful. This solution only tested on Linux (Ubuntu 16.04 & Debian 8) And for Java 1.8.*

This should be your perfect solution. Try and enjoy. If some command not work properly that means if you get any error. Try to solve it yourself. I have given you main thing that you need. if your application in different location, Or your system architecture is different. solve it yourself. Very easy to do this. Just follow my given solution.

Step 0:

sudo apt-get install openjdk-8-jre

Step: 1

sudo apt-get install openjfx

Step 2:

sudo cp /usr/share/java/openjfx/jre/lib/ext/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 3:

sudo cp /usr/share/java/openjfx/lib/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 4:

sudo chmod 777 -R /usr/lib/jvm/java-1.8.0-openjdk-amd64

now open a new project or rebuild your project. Good luck.

Upvotes: 4

Try this solution in IDEA press ctrl+shift+alt+s (File -> Project Structure) then select Project -> Project Language Level and select 8 or above.

Upvotes: 14

Ivan Pozhidaev
Ivan Pozhidaev

Reputation: 315

The JavaFX package is not included in JDK 9 and later. You need to install JDK 8, or you can add the JavaFX package separately, for example, from JDK 8 (jfxrt.jar).

Upvotes: 18

Step 1: Configuring everything to java 9

First you need to make sure everything is configured to java 9. Click on File->Project Structure

  • On the project menu you have the Project SDK and the language level (Image)

  • And on the modules menu you have to check 2 tabs (you probably have to to it for every module):

    • Souces has got the language level (Image)

    • And dependences has got the Module SDK (Image)

Step 2 Rebuilding your project

Then you need to rebuild your project:

Right-click on your project and click on Rebuild Module (Image)

Then just wait until your project is rebuilt and try to run it again.

Upvotes: 0

Related Questions