1. Linux

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:

  1. On the command line, enter the following command:
    sudo apt-get install openjfx
  2. After that, go to the project settings (ALT+CTRL+SHIFT+s) → SDKsClasspath and click the plus icon on the right. Select the jfxrt.jar file. It is located in the installed JDK at the path: <JDK_PATH>/jre/lib/ext/jfxrt.jar
  3. 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:

  1. Download the JavaFX SDK for Windows from https://gluonhq.com/products/javafx/.
  2. Unzip the downloaded archive to any folder (preferably to the lib folder of the Games project).
  3. Open IDEA.
  4. In IDEA, go to FileProject Structure...
  5. Select the Libraries tab and press +Java.
  6. Specify the path to the unpacked javafx-sdk folder and select the lib folder
  7. Then press OK. In the new window, add JavaFX to the Games module.
  8. The new library should now appear. Press ApplyOK.
  9. To start correctly, open the menu RunEdit 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

  10. Then, in the same tab, you need to add an application. To do this, press +Application
  11. Perform these steps:
    1. Select the Games module
    2. Write the path to the main class (in this case, SnakeGame)
    3. For the VM options field, enter the same value as in item 9.
    4. Press: ApplyOK
  12. Run the game.