Java 运行时在 Java 中创建按钮事件时出错



我是Java的新手。我目前正在使用 Ubuntu 16.04 并在 Java 上工作。我想创建一个按钮事件。程序代码被编译,但在运行时抛出错误。这是代码:

import java.awt.*;
import java.awt.event.*;
public class frame implements ActionListener
{
private Frame f;
private Button b;
public frame()
{
f=new Frame("My frame");
b=new Button("Press me");
b.setActionCommand("Button Pressed");
b.addActionListener(this);
}
public void launchFrame()
{
f.add(b,BorderLayout.CENTER);
f.pack();
f.setSize(170,170);
f.setBackground(Color.red);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("Action occured");
System.out.println("Button command is: "+e.getActionCommand());
}
public static void main(String[]args)
{
try
{
frame guiWindow=new frame();
guiWindow.launchFrame();
}
catch(Exception e)
{
  System.out.println(e.getMessage());
}
}
}

我得到的错误是:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fc533be1009, pid=26860, tid=26861
#
# JRE version: OpenJDK Runtime Environment (9.0) (build 9-internal+0-2016-04-14-195246.buildd.src)
# Java VM: OpenJDK 64-Bit Server VM (9-internal+0-2016-04-14-195246.buildd.src, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libjava.so+0x1d009]  JNU_GetEnv+0x19
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P" (or dumping to /home/darthronauk/core.26860)
#
# An error report file with more information is saved as:
# /home/darthronauk/hs_err_pid26860.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.
#
Aborted (core dumped)

这是我每次运行它时遇到的错误。我该怎么办?

我对Java也没有太多了解,但如果它是特定于版本的问题,您可以尝试一件事。打开终端并键入以下内容:

export LD_BIND_NOW=1

在此之后,再次运行您的 Java 代码。

解决方案的详细信息如下:http://osr507doc.sco.com/en/tools/ccs_linkedit_runtime_compat.html

相关内容

  • 没有找到相关文章

最新更新