SWT在Mac OSX上无效线程访问(Eclipse Helios) [英] SWT Invalid Thread Access on Mac OSX (Eclipse Helios)

查看:420
本文介绍了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中的异常org.eclipse.swt.SWTException:
org.eclipse.swt.SWT.error(SWT.java:4282)在
org.eclipse.swt上无效的线程访问.SWT.error(SWT.java:4197)at
org.eclipse.swt.SWT.error(SWT.java:4168)at
org.eclipse.swt.widgets.Display.error(Display .java:1065)at
org.eclipse.swt.widgets.Display.createDisplay(Display.java:822)at
org.eclipse.swt.widgets.Display.create(Display.java:805 )at
org.eclipse.swt.graphics.Device。(Device.java:130)at
org.eclipse.swt.widgets.Display。(Display.java:696)at
org.eclipse.swt.widgets.Display(Display.java:687)at
com.samples.swt.first.Main.main(Main.java:8)

***WARNING: Display must be created on main thread due to Cocoa restrictions.
Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(SWT.java:4282) at org.eclipse.swt.SWT.error(SWT.java:4197) at org.eclipse.swt.SWT.error(SWT.java:4168) at org.eclipse.swt.widgets.Display.error(Display.java:1065) at org.eclipse.swt.widgets.Display.createDisplay(Display.java:822) at org.eclipse.swt.widgets.Display.create(Display.java:805) at org.eclipse.swt.graphics.Device.(Device.java:130) at org.eclipse.swt.widgets.Display.(Display.java:696) at org.eclipse.swt.widgets.Display.(Display.java:687) at com.samples.swt.first.Main.main(Main.java:8)

就我而言告诉我,我正在做的一切正常。为什么我得到这个错误?它表示必须在主线程上创建显示,只要我能告诉它正在主线程上创建。然后继续谈论线程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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆