Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

java - Exception in thread "main" org.eclipse.swt.SWTError: XPCOM error 0x80004005 in swt.mozilla

following my SWT code which use Mozilla browser but it gives me an error xpcomm error 0x80004005.

import java.awt.GridLayout;
import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.dnd.SwtUtil;

public class Newbrowser {
    public static void main(String a[]) {
        Display display = new Display();
        Shell shell = new Shell(display);
        /* Composite controls = new Composite(shell, SWT.NONE); */
        shell.setText("Browser");
        String pathToXulrunner = "C://Program Files (x86)/Mozilla XULRunner/";

        System.setProperty("org.eclipse.swt.browser.XULRunnerPath", pathToXulrunner);

        /*
         * System.setProperty("org.eclipse.swt.browser.XULRunnerPath",
         * pathToXulrunner);
         */
        System.setProperty("org.eclipse.swt.browser.MOZ_PROFILE_PATH", new File("").getAbsolutePath());
        Browser browser = new Browser(shell, SWT.MOZILLA);
        shell.setLayout(new FillLayout());
        shell.open();

        FormData data = new FormData();

        data.top = new FormAttachment(0, 0);
        data.bottom = new FormAttachment(100, 0);
        data.left = new FormAttachment(0, 0);
        data.right = new FormAttachment(100, 0);
        browser.setLayoutData(data);
        browser.setUrl("www.google.com");

        // Set up the event loop.

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                // If no more entries in the event queue
                display.sleep();
            }
        }
        display.dispose();
    }
}

Please help me to solve this problem. thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the notes on using XULRunner here, it looks like using version 10.x is correct.

I was able to get your code running by downloading XULRunner 10.0.4esr. I followed the installation steps given in this answer, as well as pointing to the bin directory specifically.

  1. Download xulrunner-10.0.4esr.en-US.win32.sdk.zip from this directory
  2. Extract the contents and move the xulrunner directory to some location (I used c:/xulrunner, but in your case C:/Program Files (x86)/XULRunner should be fine too.
  3. Either use the VM argument (-Dorg.eclipse.swt.browser.XULRunnerPath), or use System.setProperty() as you are currently. Be sure that the path that you specify points to the bin directory, not just the top level xulrunner directory.

Make sure you have that version of XULRunner (and specifically the SDK), and verify that the file path you are pointing to exists. Depending on where you unzip the download, you may need to replace:

String pathToXulrunner = "C://Program Files (x86)/Mozilla XULRunner/";

with:

String pathToXulrunner = "C:/Program Files (x86)/Mozilla XULRunner/bin";

I'm also running 64-bit Windows 10 with SWT 4.5.2, so we should have the same setup.


Edit: I just realized I was doing this with 32-bit libraries (32-bit Java and 32-bit SWT). So if you're by any chance using 32-bit libraries, this should work. According to this answer you should be able to use XULRunner 24 with a 64-bit JRE, however I was not able to get this working.


Edit 2: For 64-bit libraries, I found the contents of the bin directory for xulrunner-1.9.2.25 here: https://osdn.net/projects/sfnet_runawfe/downloads/SRC%20and%20BIN%20files/extras/xulrunner-1.9.2.25-win64.zip/

With this downloaded, I was able to run your code. Note that this is the contents of the bin directory (equivalent to downloading the runtimes instead of the SDK), so you can exclude the bin from your file path for pathToXulrunner.

I can't right this minute, but I'll host this somewhere else and update the post later.


Edit 3: I've re-hosted this as xulrunner-1.9.2.25.en-US.win64.zip


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...