"X11 Forwarding Issue?"

7 views
Skip to first unread message

Srinidhi Kaushik

unread,
May 14, 2020, 8:54:49 AM5/14/20
to Runestone Dev
Hi Brad,

I was relearning Java from the "Java for Python Programmers" book. I experienced an error in this example code with something about the X11 DISPLAY variable. This isn't such a big deal because I understand what the code was supposed to do (based on the explanation afterward) but I am just curious as to what the solution on my end would be. All the info is beneath my signature.

Thank you so much!
-Sri



The issue is under the "Input/ Output/ Scanner" header.

The Example Code: 
_________________

import javax.swing.*;

public class TempConvGUI {

    public static void main(String[] args) {
        String fahrString;
        Double fahr, cel;

        fahrString = JOptionPane.showInputDialog("Enter the temperature in F");
        fahr = new Double(fahrString);
        cel = (fahr - 32) * 5.0/9.0;

        JOptionPane.showMessageDialog(null,"The temperature in C is, " + cel);
    }

}



The Error:

Exception in thread "main" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
        at java.desktop/java.awt.Window.(Window.java:548)
        at java.desktop/java.awt.Frame.(Frame.java:423)
        at java.desktop/java.awt.Frame.(Frame.java:388)
        at java.desktop/javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1919)
        at java.desktop/javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995)
        at java.desktop/javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689)
        at java.desktop/javax.swing.JOptionPane.showInputDialog(JOptionPane.java:580)
        at java.desktop/javax.swing.JOptionPane.showInputDialog(JOptionPane.java:527)
        at java.desktop/javax.swing.JOptionPane.showInputDialog(JOptionPane.java:475)
        at java.desktop/javax.swing.JOptionPane.showInputDialog(JOptionPane.java:439)
        at TempConvGUI.main(TempConvGUI.java:9)

Bradley Miller

unread,
May 14, 2020, 10:34:01 AM5/14/20
to runestonei...@googlegroups.com
That program is expecting to open up a Window on your computer with a GUI interface. Which is not possible to run from the browser+sandbox environment. In other words we messed up and made that example one that you can run in the browser when we should not have. If you have Java on your own computer you can save that code to a file TempConvGUI.java and then compile it and run it from there.

Brad

Bradley Miller, PhD
Professor Emeritus Computer Science
Luther College

Democratizing Textbooks for the 21st Century - Please Support Runestone
--
You received this message because you are subscribed to the Google Groups "Runestone Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to runestoneinterac...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/runestoneinteractive/473089e2-be2e-41cb-9dd9-6964c83212e2%40googlegroups.com.

Srinidhi Kaushik

unread,
May 14, 2020, 2:26:27 PM5/14/20
to Runestone Dev
Ahh, I see. I will do that instead.

Thank you for the quick response!

Sincerely,
Sri
Reply all
Reply to author
Forward
0 new messages