I am using a Raspberry Pi 2 model with Debian as the OS. I tried a simple java swing program that opens a JFrame on it, and it worked fine.
Later, I wanted to use my Pi headlessly i.e. without connecting Display, keyboard and mouse. So I connected to it using the Ethernet port. I installed the tight VNC server on the Pi and the VNC viewer client on my desktop PC.
I was able to view and operate the Pi's desktop from my PC, but when I tried to run the same Java swing program, it exited giving out Java Headless exception and sometimes an authentication error. After searching on the Internet I tried some export
DISPLAY commands, but no use.
I understand that I need to set some parameters, either relating to the JRE or the operating system.
Below is the stack
pi@raspberrypi:~/prog $ sudo java HelloSwing
Client is not authorized to connect to ServerException in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':1.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.Class.forName0(Native Method)