Internal graphics not yet initialized: javafx

I am trying to write a javaFx application with multiple images inside a window.
In short, I have an enum class called Candy , and each candy has some properties and a path to the image file representing it.
In the constructor of my javafx.application ( Table ) class, I want to populate a list of arrays with these images, so I have written this so far:

 public class Table extends Application { ArrayList<Image> images; @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("CandyFx"); primaryStage.show(); } public Table() { images = new ArrayList<Image>(); for (Candy candy : Candy.values()) { File file = new File (candy.getImagePath()); Image image = new Image(file.toURI().toString()); images.add(image); } } } 

Now every time I want to create an instance of the Table class, the application throws a java.lang.RuntimeException: Internal graphics not initialized yet .
How can I create an initial graphic that seems like I didn’t?

+5
source share
2 answers

First of all, if you are using Linux, GTK 2.18 is required to run JavaFX.try to install

 libswt-gtk-3-java 

This exception will be thrown whenever your screen is zero. Try creating your images inside the start method. Shortly before primaryStage.show(); .

Take a look at this link.

http://cr.openjdk.java.net/~vadim/RT-33475/webrev.00/modules/graphics/src/main/java/com/sun/glass/ui/Screen.java.html

+4
source

I don’t know how this works, but when we first create a JFXPanel at our beginning, we no longer get errors.

 JFXPanel jfxPanel = new JFXPanel(); 
0
source

Source: https://habr.com/ru/post/1210661/


All Articles