OSX上无效线程访问

OSX上无效线程访问

本文介绍了SWT在Mac OSX上无效线程访问(Eclipse Helios)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最简单的简单的SWT程序(它甚至不显示你好世界):

I have the simplest of all simple SWT programs (it doesn't even display hello world yet):

package com.samples.swt.first;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Main {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}

当我从Eclipse Helios在Mac OSX上运行时,我收到以下错误:

When I run this on Mac OSX from Eclipse Helios, I get the following error:

就我而言告诉我,我正在做的一切正常。为什么我得到这个错误?它表示必须在主线程上创建显示,只要我能告诉它正在主线程上创建。然后继续谈论线程main中的异常 ...

As far as I can tell, I am doing everything correctly. Why am I getting this error? It says that Display must be created on the main thread, and as far as I can tell it is being created on the main thread. It then goes on to talk about Exception in thread "main"...

编辑: / strong>

现在,错误已经消失,我从使用 swt-debug.jar 切换到 SWT.JAR 。如果有人知道为什么调试jar会导致这个错误,我很想知道...

The error is gone now, I switched from using swt-debug.jar to swt.jar. If anybody knows why the debug jar causes this error I would love to know...

推荐答案

你需要有-XstartOnFirstThread开始应用程序时切换。 SWT常见问题解答中的解释了原因。

You need to have the -XstartOnFirstThread switch when starting the application. This question on the SWT FAQ explains the reasons.

这篇关于SWT在Mac OSX上无效线程访问(Eclipse Helios)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 16:08