0

I'm trying to run a Java application on Xubuntu 14.04, but I always get

java.lang.InternalError: Can't connect to X11 window server using ':0.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:110)
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:190)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:119)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at java.awt.Toolkit$2.run(Toolkit.java:868)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:860)

echo $DISPLAY returns :0.0

What could be wrong here?

Jan Krakora
  • 2,500
  • 3
  • 25
  • 52
  • Are you running an X server? That is, is there one for it to connect to? – Avery May 29 '14 at 14:51
  • I'm a linux beginner, but I've just installed Xubuntu distro (with desktop), so I assume there is a X server running. – Jan Krakora May 29 '14 at 14:54
  • 1
    Try one of advises from http://stackoverflow.com/questions/10165761/java-cant-connect-to-x11-window-server-using-localhost10-0-as-the-value-of-t – Artur Malinowski May 29 '14 at 14:57
  • Does `echo $DISPLAY` return "0.0" or ":0.0"? It _should_ return the latter. – Avery May 29 '14 at 14:59
  • Setting system property java.awt.headless to true helps but then I get java.awt.HeadlessException. It's not the solution for me. I need headfull JVM. – Jan Krakora May 29 '14 at 15:07
  • Just checking - you're actually working on a display, keyboard, mouse, etc __directly__ connected to the computer? – Avery May 29 '14 at 15:09
  • 1
    Are you launching this from a shell? Do other X programs (try `xterm`) work when attempted from the same place? – nobody May 29 '14 at 15:10
  • Yes, I do. It's standard desktop Xubuntu distro. – Jan Krakora May 29 '14 at 15:11
  • @AndrewMedico xterm works (at least it opens a terminal), my application is a J2EE, so I launch the Tomcat ($ sudo /etc/init.d/tomcat7 start) – Jan Krakora May 29 '14 at 15:14
  • The `sudo` is the problem - X has a permissions system and users other than the one who launched the X session aren't allowed to use it by default (otherwise they could do nasty things like run keyloggers in your X session). Also, running X programs from Tomcat seems like an... odd design. – nobody May 29 '14 at 15:16
  • Well, my application generates off-screen images and not all AWT code is headless compatible. So the X server is running under myself when I start the OS, right? And when I run Tomcat as root, it can't connect to the X server? What is the solution to this? – Jan Krakora May 29 '14 at 20:19

2 Answers2

0

Well it's been quite a while since this questions was posted. Nevertheless I'm going to provide a solution , The solution for this problem is to run android studio without SUDO

So , if you're doing this on the terminal :-

sudo ./studio.sh

change it to this and it should work .

./studio.sh
TheAnimatrix
  • 566
  • 1
  • 6
  • 19
0

I solved this issue by re-installing the XMING driver

Evidently, a windows update removed it.

Lcat
  • 857
  • 1
  • 8
  • 16