gpt4 book ai didi

java - 从 IntelliJ 运行 JavaFX 和 Swing 时出现段错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:19 24 4
gpt4 key购买 nike

从 IntelliJ 2016.1 社区版运行以下缩小示例时,我总是遇到段错误:

import javax.swing.*;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Repro extends Application {

public static void main(String[] args) {
JFrame swingFrame = new JFrame();
swingFrame.setTitle("Repro start");
swingFrame.setSize(200, 350);
swingFrame.setVisible(true);

Application.launch(args);
}

@Override
public void start(Stage stage) throws Exception {
Pane root = new Pane();
root.setMinHeight(200);
root.setMinWidth(350);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}

环境如下:

  • Ubuntu 15.10
  • openjdk-8(1.8.0_u66 构建 17)
  • openjfx-8 (8u60-b27-4)
  • IntelliJ 2016.1 社区版(build #IC-145.258)

java
中运行 javac 无法重现该问题通过oraclejdk(1.8.0_u77-b03)运行也没有显示问题

作为引用,程序的“输出”如下:

Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" #
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (safepoint.cpp:712), pid=16937, tid=140197878814464
# fatal error: Illegal threadstate encountered: 6
#
# JRE version: OpenJDK Runtime Environment (8.0_66-b17) (build 1.8.0_66-internal-b17)
# Java VM: OpenJDK 64-Bit Server VM (25.66-b17 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/vogel612/.../hs_err_pid16937.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#

Process finished with exit code 134

运行 ulimit -c unlimited 并重新启动 IntelliJ 后问题仍然存在

根据要求,此类执行的错误日志可在 this gist. 获得。

我该如何解决这个问题?

最佳答案

错误可以在 IntelliJ 之外重现,如下所示。

public class Main {
public static void main(String[] args) throws Exception {
new Repro().main(new String[0]);
}
}

运行 java -cp 。 Main 在 Ubuntu 15.10 上有

openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)
OpenJDK 64-Bit Server VM (build 25.66-b17, mixed mode)

产生相同的 fatal error 。而运行 java -cp 。 repo 不会失败。

运行 java -cp 。 CentOS 7 上的主

openjdk version "1.8.0_77"
OpenJDK Runtime Environment (build 1.8.0_77-b03)
OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode)

打开 Swing JFrame 和 JavaFX Pane 。

似乎这个问题与特定的 OpenJDK 版本和类 Repo 的调用方式有关。

编辑 如果您不能切换到另一个 Java 版本,则有一个可能的“解决方法”。 (基于此 post )

修改你的 Repro.java 如下,它不会在 OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)

上失败
public static void main(String[] args) throws Exception {
new JFXPanel(); // the "workaround" to initialize the toolkit
JFrame swingFrame = new JFrame();
...

关于java - 从 IntelliJ 运行 JavaFX 和 Swing 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36284944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com