If you are using Linux and OpenJDK, there is a chance that the compiler will throw an error when you run the game:
Error:(6, 8) java: cannot access javafx.application.Application class file for javafx.application.Application not found
What should you do?
The issue here is that the CodeGym game engine uses the JavaFX library, but OpenJDK does not install this library by default. This needs to be fixed:
- On the command line, enter the following command:
sudo apt-get install openjfx
- After that, go to the project settings (ALT+CTRL+SHIFT+s) → SDKs → Classpath and click the plus icon on the right. Select the
jfxrt.jarfile. It is located in the installed JDK at the path:
- Click OK.
2. JDK 11+
You may also encountering problems running the game if you are using JDK version 11 or later: Java JDK 11 no longer includes the JavaFX library. That means that when you run the game, the compiler won't be able to compile it, and there will be an error. To fix the problem, you need to add JavaFX to the project:
- Download the JavaFX SDK for Windows from https://gluonhq.com/products/javafx/.
- Unzip the downloaded archive to any folder (preferably to the
libfolder of the Games project).
- Open IDEA.
- In IDEA, go to File → Project Structure...
- Select the Libraries tab and press + → Java.
- Specify the path to the unpacked
javafx-sdkfolder and select the
- Then press OK. In the new window, add JavaFX to the Games module.
- The new library should now appear. Press Apply → OK.
- To start correctly, open the menu Run → Edit configuration, and in the VM options: field, write the following:
--module-path ./lib/javafx-sdk-16/lib --add-modules=javafx.controls,javafx.fxml,javafx.base
In recent versions of IntelliJ IDEA, the "VM options" field is not shown by default. To display it, press ALT+V
- Then, in the same tab, you need to add an application. To do this, press + → Application
- Perform these steps:
- Select the Games module
- Write the path to the main class (in this case,
- For the VM options field, enter the same value as in item 9.
- Press: Apply → OK
- Run the game.