1

I tried to execute a java swing program in ubuntu 16.04, it is working fine with the default user, but when i change the user it is not working and showing the following error.

    No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':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 java.awt.Frame.<init>(Frame.java:385)
    at javax.swing.JFrame.<init>(JFrame.java:189)
    at ImageButton.<init>(ImageButton.java:6)
    at ImageButton.main(ImageButton.java:23)

can any one help me with this please.

karthi
  • 549
  • 3
  • 15
  • 26
  • did you see http://stackoverflow.com/questions/10165761/java-cant-connect-to-x11-window-server-using-localhost10-0-as-the-value-of-t? – Apostolos Jun 14 '16 at 09:24
  • Yeah, i have seen that but that didn't solve my problem. – karthi Jun 14 '16 at 09:37
  • Have you also seen the other answer which suggests setting the headless flag? – Fildor Jun 14 '16 at 10:28
  • yes i tried it, it is giving the following exception: Exception in thread "main" java.awt.He adlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:1 73) – karthi Jun 14 '16 at 10:42
  • Is that other user 'root' specifically or in general some other user? – dbalakirev Aug 24 '17 at 13:20

1 Answers1

0

if the user of java awt process is not you(who login into a desktop), it may not pass the xauth. try to share your .Xauthority to that user by:

export XAUTHORITY=/home/<you>/.Xauthority
fatfatson
  • 796
  • 10
  • 24