Java – SWT invalid thread access on Mac OSX (eclipse Helios)

I have the simplest of all simple SWT programs (it doesn't even show Hello World):

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();
    }
}

When I run it from eclipse Helios on Mac OSX, I get the following error:

As far as I know, I'm doing everything normal Why did I get this mistake? It means that the display must be created on the main thread, and as far as I know, it is being created on the main thread Then continue to talk about exceptions in thread "main"

Edit:

Now that the error has disappeared, I started using SWT debug Switch to SWT. Jar jar. If anyone knows why debugging bottles leads to this error, I'd like to know

Solution

When starting the application, you need to use the - xstartonfirstthread switch The SWT FAQ in this question explains why

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>