0

I can't get OpenJFX to work in my project. I importet the library into my IntelliJ project and it resolved all the build errors but when i start my program nothing happens. The console doesn't give me any output. The program starts and then runs indefinitly without showing anything. When i stop the program it says Process finished with exit code 130 (interrupted by signal 2: SIGINT)

Main.java

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
    }

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Binary Clock");
        stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("clock_gui.fxml"))));
        stage.show();
    }
}

clock_gui.fxml (created by the SceneBuilder)

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>


<AnchorPane prefHeight="276.0" prefWidth="344.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ClockGui">
   <children>
      <HBox layoutX="100.0" layoutY="125.0" spacing="4.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <VBox id="hour_tenner" prefWidth="50.0" spacing="4.0">
               <children>
                  <Rectangle id="ht8" fx:id="ht8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Rectangle>
                  <Rectangle id="ht4" fx:id="ht4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="ht2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="ht1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
               </children>
            </VBox>
            <VBox id="hour_single" prefWidth="50.0" spacing="4.0">
               <children>
                  <Rectangle id="hs8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Rectangle>
                  <Rectangle id="hs4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="hs2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="hs1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
               </children>
            </VBox>
            <VBox id="minute_tenner" prefWidth="50.0" spacing="4.0">
               <children>
                  <Rectangle id="mt8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Rectangle>
                  <Rectangle id="mt4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="mt2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="mt1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
               </children>
            </VBox>
            <VBox id="minute_single" prefWidth="50.0" spacing="4.0">
               <children>
                  <Rectangle id="ms8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Rectangle>
                  <Rectangle id="ms4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="ms2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
                  <Rectangle id="ms1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" spacing="4.0">
               <children>
                  <Button fx:id="start" mnemonicParsing="false" onMouseClicked="#ClockGui" prefHeight="30.0" prefWidth="64.0" text="start">
                     <VBox.margin>
                        <Insets bottom="102.0" />
                     </VBox.margin>
                  </Button>
                  <HBox prefHeight="100.0" prefWidth="200.0" spacing="4.0">
                     <children>
                        <VBox id="second_tenner" prefWidth="50.0" spacing="4.0">
                           <children>
                              <Rectangle id="st8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0">
                                 <VBox.margin>
                                    <Insets />
                                 </VBox.margin>
                              </Rectangle>
                              <Rectangle id="st4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                              <Rectangle id="st2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                              <Rectangle id="st1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                           </children>
                        </VBox>
                        <VBox id="second_single" prefWidth="50.0" spacing="4.0">
                           <children>
                              <Rectangle id="ss8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0">
                                 <VBox.margin>
                                    <Insets />
                                 </VBox.margin>
                              </Rectangle>
                              <Rectangle id="ss4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                              <Rectangle id="ss2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                              <Rectangle id="ss1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
                           </children>
                        </VBox>
                     </children>
                  </HBox>
               </children>
            </VBox>
         </children>
         <padding>
            <Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
         </padding>
      </HBox>
   </children>
</AnchorPane>

ClockGui.java (as the Controller)

import javafx.fxml.FXML;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class ClockGui {

    @FXML
    private Rectangle ht8;

    public ClockGui(){
        ht8.setFill(Color.rgb(225,250,30));
    }
}

I'm on Ubuntu 18.04.2 LTS.

mr.jogurt
  • 43
  • 8

1 Answers1

2

You say you start the VM, but it does "nothing". The reason for that is in your main:

public static void main(String[] args) {
}

That's the entry point to your application, but you are not asking it to call your application class...

As you can read from the (Javadoc](https://openjfx.io/javadoc/12/javafx.graphics/javafx/application/Application.html#launch(java.lang.String...)), this is the required method to launch an standalone application, and it is usually called from main.

Just add this:

public static void main(String[] args) {
    launch(args);
}

and run again.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • now it works thanks. since when do you need to do this? now i get this error: ```Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5dc01701) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x5dc01701 ``` any idea how i can fix this? – mr.jogurt May 25 '19 at 20:10
  • Usually you don't need to add `main`, your IDE will launch the Application for you. However, if you do add `main`, you need to include `launch`. It is like if you are overriding main, so to speak. – José Pereda May 25 '19 at 20:12
  • 1
    You need to add the `javafx.fxml` module to your VM options. I suggest you have a look at the documentation: https://openjfx.io/openjfx-docs/#IDE-Intellij – José Pereda May 25 '19 at 20:13