connelblaze
connelblaze

Reputation: 793

Headless exception on cloud9 ide

import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class noteMenu{
    //main menu method
    private static void addContents(Container pane){
        JButton btn;
        pane.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        //Insets gbc = new insets(5,3,5,3);
        btn = new JButton("Create a note");
        gbc.gridx = 0;
        gbc.gridy = 0;
        pane.add(btn, gbc);
        //
        btn = new JButton("Open note");
        gbc.gridx = 2;
        gbc.gridy = 2;
        pane.add(btn, gbc);
    }
    private static void mainMenu(){
        JFrame note = new JFrame("CB Note app");
        JFrame.setDefaultLookAndFeelDecorated(true);
        note.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //set up contentpane
        addContents(note.getContentPane());
        note.pack();
        note.setVisible(true);
        note.setSize(500,300);
    }

    //main method
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                mainMenu();
           }
        });
    }
}

then i compile and i had this exception raised:

Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207) at java.awt.Window.(Window.java:535) at java.awt.Frame.(Frame.java:420) at javax.swing.JFrame.(JFrame.java:218) at noteMenu.mainMenu(noteMenu.java:23) at noteMenu.access$000(noteMenu.java:5) at noteMenu$1.run(noteMenu.java:37) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745) at java.awt.EventQueue.access$300(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:706) at java.awt.EventQueue$3.run(EventQueue.java:704) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:715) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Tried sudo apt-get install default-jdk. But that didn't solve the issue. What should i do?

Upvotes: 0

Views: 174

Answers (1)

Brady Dowling
Brady Dowling

Reputation: 5532

You may have seen this but this question answers your question as well: Running Java GUI apps on Cloud 9

It is not possible to run GUI programs on Cloud9.

Upvotes: 1

Related Questions