无法使用 Ubuntu 运行 Java GUI 程序 [英] Unable to run Java GUI programs with Ubuntu

查看:27
本文介绍了无法使用 Ubuntu 运行 Java GUI 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Java 学习 GUI,为此我创建了一个演示程序:

I am learning GUI in Java, and for that I have created a demo program:

import java.awt.*;

public class FrameDemo extends Frame {

    public FrameDemo(){
        super("Frame Demo");
        setSize(200, 200);
        setVisible(true);
    }

    public static void main(String args[]){
        new FrameDemo();    
    }
}

编译成功.但是当我尝试执行该程序时,发现了以下错误:

It was compiled successfully. But when I tried to execute the program, I found the following error:

Exception in thread "main" java.awt.HeadlessException
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:173)
    at java.awt.Window.<init>(Window.java:437)
    at java.awt.Frame.<init>(Frame.java:419)
    at FrameDemo.<init>(FrameDemo.java:4)
    at FrameDemo.main(FrameDemo.java:9)

我正在使用 Xubuntu 10.10 并且 java -version 给出:

I am using Xubuntu 10.10 and java -version gives:

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)

我该怎么办?

还有一点:当我尝试执行 Dr. Java 和 HJSplit 的 jar 文件时,我遇到了同样的错误.

One more thing: It is the same sort of error I got when I tried to execute Dr. Java and HJSplit's jar file.

推荐答案

Ubuntu 可以选择安装 headless Java —— 这意味着没有图形库.情况并非总是如此,但前几天我在 10.10 上尝试运行 Java 文本编辑器时遇到了这个问题.运行以下命令以安装具有这些库的 JDK:

Ubuntu has the option to install a headless Java -- this means without graphics libraries. This wasn't always the case, but I encountered this while trying to run a Java text editor on 10.10 the other day. Run the following command to install a JDK that has these libraries:

sudo apt-get install openjdk-6-jdk

实际上,查看我的配置,您可能需要 JRE.如果是这种情况,请运行:

Actually, looking at my config, you might need the JRE. If that's the case, run:

sudo apt-get install openjdk-6-jre

这篇关于无法使用 Ubuntu 运行 Java GUI 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆