0

I'm trying to get the current Display in a Java application (on Netbeans) but it keep throwing an Exception for which I find nothing usefull on the web.

This is my code:

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        try {
        System.out.println("Step 1 in Execute in EmailHandler.");
        Display display = Display.getCurrent();
//        Display display = PlatformUI.getWorkbench().getDisplay();
        System.out.println("Step 2 in Execute in EmailHandler.");
        Shell shell = new Shell(display);
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        // This should start outlook if it is not running yet
        OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
        System.out.println("Step in Execute in EmailHandler.");
        site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
        // now get the outlook application
        OleClientSite site2 = new OleClientSite(frame, SWT.NONE, "Outlook.Application");
        OleAutomation outlook = new OleAutomation(site2);

        OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */).getAutomation();
        setProperty(mail, "To", "[email protected]"); // Empty but could also be predefined
        setProperty(mail, "Bcc", "[email protected]");
        setProperty(mail, "BodyFormat", 2 /* HTML */);
        setProperty(mail, "Subject", "Test mail");
        setProperty(mail, "HtmlBody","<html>Hello<p>, please find some infos here.</html>");
        File file = new File("c:/temp/test.txt");
        if (file.exists()) {
          OleAutomation attachments = getProperty(mail, "Attachments");
          invoke(attachments, "Add", "c:/temp/test.txt");
        } else {
          MessageDialog.openInformation(shell, "Info","Attachment File c:/temp/test.txt not found; will send email with attachment");
        }
        invoke(mail, "Display"/*"Send"*/); // Or "Display" in place of "Send"
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        return null;
    }

The Exception occur at the line Display display = Display.getCurrent(); And as you see on the next line, I tried to get the current display by another way but I still get an error.

This is the error I get with the Display.getCurrent() method:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3139 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:123)
    at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:19)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:54)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:122)
    at costPolicy_v1.EmailHandler.execute(EmailHandler.java:35)
    at costPolicy_v1.CostPolicyFrame.startButtonActionPerformed(CostPolicyFrame.java:304)
    at costPolicy_v1.CostPolicyFrame.access$300(CostPolicyFrame.java:27)
    at costPolicy_v1.CostPolicyFrame$4.actionPerformed(CostPolicyFrame.java:169)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    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)

Here are my imports:

import java.io.File;
import javax.swing.JOptionPane;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

Does someone know a solution for that ?

Thank you very much !

1 Answer 1

0

I discover my problem ! I added the SWT.jar as a jar and not as an entire library. Now that I added it as a library, the exception is no more throwed ! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.