【问题标题】:Cannot run Swing programs on ubuntu 14.04无法在 ubuntu 14.04 上运行 Swing 程序
【发布时间】:2016-10-17 02:39:59
【问题描述】:

我必须为一个类做一个 GUI 项目,但我无法运行我正在编写的程序。我到处找,所以我尝试运行最简单的程序:

package start; 
/*
* HelloWorldSwing.java requires no other files. 
*/
  import javax.swing.*;        

  public class HelloWorldSwing {
  /**
  * Create the GUI and show it.  For thread safety,
  * this method should be invoked from the
  * event-dispatching thread.
  */
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("HelloWorldSwing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add the ubiquitous "Hello World" label.
    JLabel label = new JLabel("Hello World");
    frame.getContentPane().add(label);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
    }
}

我有 java 编译器,我知道,因为当我在终端上使用 java -version 时,它会返回:

openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195526.buildd.src)
OpenJDK Client VM (build 9-internal+0-2016-04-14-195526.buildd.src, mixed mode)

我也有 JRE。

当我编译它时,我使用javac start/HelloWorldSwing.java(它确实编译) 但是当我尝试使用java start.HelloWorldSwing 运行它时,它会返回:

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xb6aafe48, pid=4166, tid=4180
#
# JRE version: OpenJDK Runtime Environment (9.0) (build 9-internal+0-2016-04-14-195526.buildd.src)
# Java VM: OpenJDK Client VM (9-internal+0-2016-04-14-195526.buildd.src, mixed mode, serial gc, linux-x86)
# Problematic frame:
# C  [libjava.so+0x18e48]  JNU_GetEnv+0x18
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to /home/carcamo/Escritorio/myhw/core.4166)
#
# An error report file with more information is saved as:
# /home/carcamo/Escritorio/myhw/hs_err_pid4166.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

如果我能在这个问题上得到任何帮助,我将不胜感激

【问题讨论】:

  • 这看起来不像是来自 Java 程序本身的错误,而是来自 JVM。如果您还没有这样做,也许是时候在该机器上重新安装 Java,因为它可能已损坏。
  • 程序在最新版本的 9 ea b143 (jdk9.java.net/download) 中的 Oracle 二进制文件中运行良好

标签: java swing ubuntu


【解决方案1】:

您是否尝试过使用受支持的 Java 版本?尝试 openjdk 8,或下载 Oracle Java 8 版本(当前为 8u102)。

【讨论】:

    猜你喜欢
    • 2014-08-08
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 2016-07-08
    相关资源
    最近更新 更多