0

I need help to create a bundle in Kura that show a Swing's GUI. I'm using Java and OSGI to create bundles. I run it on raspberryPI.

I put this code inside the bundle's activator:

public void activate(ComponentContext componentContext, Map<String,Object> properties)
{
    System.out.println("Sono AstroGUI!!!!");

    Runnable runnable = new Runnable() {
          public void run() {
        createAndShow();
          }
        };
        SwingUtilities.invokeLater(runnable);
}

 static void createAndShow() {


    JFrame frame = new JFrame("Hello World");
    frame.setSize(640,480);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }

But when I upload the bundle, the system return this error:

Exception in thread "AWT-EventQueue-0" 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:207) at java.awt.Window.(Window.java:536) at java.awt.Frame.(Frame.java:420) at javax.swing.JFrame.(JFrame.java:225) at com.riccardofontanini.astrogui.AstroGUIActivator.createAndShow(AstroGUIActivator.java:56) at com.riccardofontanini.astrogui.AstroGUIActivator$1.run(AstroGUIActivator.java:47) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744) at java.awt.EventQueue.access$400(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.awt.EventQueue$3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:714) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Please help me!

Robin V.
  • 1,484
  • 18
  • 30
  • 1
    [Maybe this](http://stackoverflow.com/questions/20648809/raspberry-pi-no-x11-display-variable-was-set-but-this-program-performed-an-ope) or [this](http://stackoverflow.com/questions/5218870/getting-a-headlessexception-no-x11-display-variable-was-set) – MadProgrammer May 02 '16 at 08:52
  • or check this http://stackoverflow.com/a/5218891/4606266 – ziLk May 02 '16 at 12:05

1 Answers1

3

Certainly make sure X11 is setup properly as previously suggested. You can also try to edit the start up script for Kura to ensure X is ready when Kura starts. The start up scripts are located in /opt/eclipse/kura/bin. The default script that Kura uses on boot is start_kura_background.sh. Edit this file and add the following lines:

if ! xset q &>/dev/null; then
    echo “Starting X Server...”
    su -s /bin/bash -c xinit root& export DISPLAY=:0
    echo “X Server started !”
else
    echo “X Server already running, DISPLAY variable setted”

Also, what version of Java are you using? I have only seen this work on a full Oracle JRE. I have not tried Eclipse Kura + Swing on OpenJDK, and it will not work on Java Embedded.

Thanks,

--Dave

David Woodard
  • 461
  • 2
  • 4
  • Hi, (I'm using eurotech's esf) I put DISPLAY=localhost:0.0 in /opt/eurotech/esf/bin/start_kura_debug_background.sh and this solve the DISPLAY problem, but now there is another one: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit I think this is a Java problem... or I must pack somethink in my bundle... – Riccardo Fontanini May 03 '16 at 13:06