Unable to run Java GUI programs with Ubuntu

前端 未结 9 748
天命终不由人
天命终不由人 2020-12-03 04:28

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(){
           


        
相关标签:
9条回答
  • 2020-12-03 04:58

    Check what your environment variable DISPLAY's value is. Try running a simple X application from the command line. If it works, check DISPLAY's value for the right value.

    You can experiment with different values of and environment variable on a per invocation basis by doing the following on the command line:

    DISPLAY=:0.0 <your-java-executable-here>
    

    How are you calling your program?

    0 讨论(0)
  • 2020-12-03 05:05

    Check your X Window environment variables using the "env" command.

    0 讨论(0)
  • 2020-12-03 05:08

    I stopped getting this exception when I installed default-jdk using apt. I'm running Ubuntu 14.04 (Trusty Tahr), and the problem appears to have been the result of having a "headless" Java installed. All I did was:

    sudo apt-get install default-jdk
    
    0 讨论(0)
  • 2020-12-03 05:09

    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
    

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

    sudo apt-get install openjdk-6-jre
    
    0 讨论(0)
  • 2020-12-03 05:11

    In my case

    -Djava.awt.headless=true
    

    was set (indirectly by a Maven configuration). I had to actively use

    -Djava.awt.headless=false
    

    to override this.

    0 讨论(0)
  • 2020-12-03 05:12

    I would check with another Java implementation/vendor. Preferrably Oracle/Sun Java: http://www.java.com/en/ . The open-source implementations unfortunately differ in weird ways.

    0 讨论(0)
提交回复
热议问题