java 内部图形尚未初始化:javafx
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27839441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Internal graphics not initialized yet: javafx
提问by AliLotfi
I'm trying to write a javaFx
application whit multiple images inside a window.
The short story is that I have an enum
class named Candy
and each candy has some properties and a path to the image file representing it.
In the constructor of my javafx.application
class (Table
) I want to fill an array list with those images, so I wrote this so far:
我正在尝试javaFx
在一个窗口中编写一个包含多个图像的应用程序。
简短的故事是,我有一个enum
名为的类Candy
,每个糖果都有一些属性和表示它的图像文件的路径。
在我的javafx.application
类 ( Table
)的构造函数中,我想用这些图像填充一个数组列表,所以到目前为止我写了这个:
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 Table
class, the application throws a java.lang.RuntimeException: Internal graphics not initialized yet
.
How can I initial graphics which it seems I did not?
现在每次我想创建一个Table
类的实例时,应用程序都会抛出一个java.lang.RuntimeException: Internal graphics not initialized yet
.
我怎样才能初始化似乎我没有的图形?
采纳答案by Saeed Masoumi
First of all if you are using linux ,GTK 2.18 is required to run JavaFX .try to install
首先,如果您使用的是 linux,则需要 GTK 2.18 才能运行 JavaFX。尝试安装
libswt-gtk-3-java
This exception will thrown whenever your screen is null .Try to create your images inside start
method. Just before the primaryStage.show();
.
只要您的屏幕为空,就会抛出此异常start
。尝试在方法中创建您的图像。就在primaryStage.show();
.
Take a look at this link too
也看看这个链接
回答by Lingkar
I have no idea how it exactly works, but when we first create a JFXPanel in our start we don't get the errors anymore.
我不知道它究竟是如何工作的,但是当我们在开始时第一次创建 JFXPanel 时,我们不会再收到错误消息。
JFXPanel jfxPanel = new JFXPanel();