CentOS中独立应用程序中的SWT浏览器不起作用:SWTError:未知错误

时间:2016-12-13 11:55:11

标签: java browser centos swt

在努力让示例代码工作的同时,我总是偶然发现这个异常:

Exception in Thread "main" org.eclipse.swt.SWTError: Unknown error
at org.eclipse.swt.internal.mozilla.nsISupport.getMethodIndex(Unknown Source)
at org.eclipse.swt.internal.mozilla.nsIFile.Create(Unknown Source)
at org.eclipse.swt.browser.AppFileLocProvider.<init>(Unknown Source)
at org.eclipse.swt.browser.Mozilla.create(Unknown Source)
at org.eclipse.swt.browser.Browser.<init>(Unknown Source)
at test.createContent(Unknown Source)
...

在其他问题描述中使用Google搜索时,如果缺少文件夹(https://www.eclipse.org/forums/index.php/t/1074640/),则表示它无法在Windows上工作({{3}})

(在Windows上,这个例子在我的电脑上工作正常,在CentOS 6.8上它失败了。)

package test; 

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.swt.SWT; 
import org.eclipse.swt.browser.Browser; 
import org.eclipse.swt.layout.GridData; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 

/**
 * code derived from http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.swt.this.swtBrowser.this.swtBrowser
 */
public class SWTTest {

   public static Display swtDisplay = null;

   private Shell   swtShellParent;
   private Shell   swtShell;
   private Browser swtBrowser;
   private Composite comp; 

  public static void main(String[] args) {
    SWTTest SWTTest = new SWTTest();
    System.exit(0);
  }

  public SWTTest() {
    if (SWTTest.swtDisplay == null) {
      SWTTest.swtDisplay = new Display();
    }
    this.swtShellParent = new Shell(SWTTest.swtDisplay, SWT.NO_TRIM|SWT.BORDER | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.RESIZE);
    try {
      createContent(new URL ("https://www.google.com"));
    }
    catch (MalformedURLException e) {}

    this.swtShell.open();
    //    SwtWebdriverWrapper.swtDisplay.asyncExec(this);
    while (true && (!swtShell.isDisposed())) {
      try {
        if (!SWTTest.swtDisplay.readAndDispatch())
          SWTTest.swtDisplay.sleep();
      } catch (Throwable t) {
        System.out.println("SwtEventDispatcher error: "+t.getMessage());
      }
    }
  }

  private void createContent(URL url) {
          this.swtShell = new Shell(this.swtShellParent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

          final GridLayout dialogShellLayout = new GridLayout();
          dialogShellLayout.makeColumnsEqualWidth = true;
          this.swtShell.setText("Html Report this.swtBrowser");
          this.swtShell.setLayout(dialogShellLayout);
          this.swtShell.layout();
          this.swtShell.pack();
          this.swtShell.setSize(800, 600);

          this.swtBrowser = new Browser(this.swtShell, SWT.NONE | SWT.BORDER);
          final GridData browserLData = new GridData();
          browserLData.widthHint = 784;
          browserLData.heightHint = 500;
          this.swtBrowser.setLayoutData(browserLData);
          this.swtBrowser.setUrl(url.toExternalForm());

          comp = new Composite(this.swtShell, SWT.NONE);
          final GridLayout compLayout = new GridLayout();
          compLayout.makeColumnsEqualWidth = true;
          compLayout.numColumns = 4;
          compLayout.marginLeft = 330;
          compLayout.marginRight = 330;
          final GridData compLData = new GridData();
          compLData.widthHint = 521;
          compLData.heightHint = 33;
          comp.setLayoutData(compLData);
          comp.setLayout(compLayout);

          this.swtShell.setLocation(this.swtShellParent.toDisplay(100, 100));
      }
}

有没有人知道我必须做些什么来使这个例子也适用于CentOS?

@edit: 这是在添加我的第一条评论中提到的配置文件夹($ HOME / .mozilla / eclipse)之后发生的:

#  SIGSEGV (0xb) at pc=0x000000335860e1dc, pid=10872, tid=140201848162048
#
# JRE version: Java(TM) SE Runtime Environment (8.0_66-b17) (build 1.8.0_66-b17)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.66-b17 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [ld-linux-x86-64.so.2+0xe1dc]

Stack: [0x00007f83494b4000,0x00007f83495b5000],  sp=0x00007f83495b3140,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ld-linux-x86-64.so.2+0xe1dc]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.eclipse.swt.internal.mozilla.XPCOM._NS_InitXPCOM2(JJJ)I+0
j  org.eclipse.swt.internal.mozilla.XPCOM.NS_InitXPCOM2(JJJ)I+11
j  org.eclipse.swt.browser.Mozilla.initXPCOM(Ljava/lang/String;Z)V+571
j  org.eclipse.swt.browser.Mozilla.create(Lorg/eclipse/swt/widgets/Composite;I)V+250
j  org.eclipse.swt.browser.Browser.<init>(Lorg/eclipse/swt/widgets/Composite;I)V+81
...

0 个答案:

没有答案