【问题标题】:Java Run time Error while creating a button event in Java在 Java 中创建按钮事件时出现 Java 运行时错误
【发布时间】:2018-01-28 17:28:51
【问题描述】:

我是 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)

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

【问题讨论】:

  • FWIW,你使用的操作系统无关紧要。

标签: java linux ubuntu button event-handling


【解决方案1】:

我对 Java 也不太了解,但如果是版本特定的问题,您可以尝试一件事。 打开终端并输入:

export LD_BIND_NOW=1

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

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

【讨论】:

    猜你喜欢
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 2021-09-09
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    相关资源
    最近更新 更多