I have a problem working connecting to X11 and DISPLAY variable
I'm working with a Java file in my Raspberry Pi Zero that is using JFrame and I want the window created by JFrame to show up in a monitor that is connected to my Raspberry, but I keep getting this exception. Any ideas? I'm working with Java OpenJDK version "1.8.0_312"
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at java.awt.Window.initGC(Window.java:475)
at java.awt.Window.init(Window.java:495)
at java.awt.Window.<init>(Window.java:537)
at java.awt.Frame.<init>(Frame.java:420)
at javax.swing.JFrame.<init>(JFrame.java:233)
at Prueba.main(Prueba.java:5)
I tried to start xterm or xhost to check everything was working fine but I have this problem:
No protocol specified
xterm: Xt error: Can't open display: :0
I am using Putty as my SSH client.
I just got it, it was as simple as writing sudo java -jar
instead of java -jar
, not sure why but it works now