+ 1

I've compiled the code and tried running it but i still receive a error.

import javax.swing.*; public class Array { public static void main(String [] arg) { String namn; String hälsning; namn = JOptionPane.showInputDialog ("Vad heter du"); hälsning = "Välkommen" + namn; JOptionPane.showMessageDialog(null, hälsning); } } //error message is as the following Exception in thread "main" 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:204) at java.awt.Window.<init>(Window.java:536) at java.awt.Frame.<init>(Frame.java:420) at java.awt.Frame.<init>(Frame.java:385) at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763) at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838) at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1696) at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:576) at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:524) at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:474) at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:440) at himynameis.main(himynameis.java:8) //using Codeanywhere.

10th Dec 2018, 10:53 AM
Henrik Engström
2 Respostas
+ 5
If you tried this in Sololearn Code Playground then No GUI frameworks are supported in the Sololearn Code Playground. So you might be getting the errors.
10th Dec 2018, 11:27 AM
Nova
Nova - avatar
0
thinking i should maybe change JOptionPane.showMessageDialog(null, hälsning); to System.out.print("Vad heter du");
10th Dec 2018, 2:13 PM
Henrik Engström