2

I'm working on a context simulator named siafu, just the first step, try to build and run it on Mac OSX 10.6.8, but I'm confused that it fails to run with Exception:

***WARNING: Display must be created on main thread due to Cocoa restrictions.
Exception in thread "GUI thread" org.eclipse.swt.SWTException: Invalid thread access
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.widgets.Display.error(Unknown Source)
    at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
    at org.eclipse.swt.widgets.Display.create(Unknown Source)
    at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
    at de.nec.nle.siafu.graphics.GUI.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:680)

The script to run is like this, can anyone kindly point out why do we have exception even though we have specify the -XstartOnFirstThread?

#!/bin/sh

if [ "$1" = "-h" ]; then echo "Syntax: $0 [SimulationJarFile]"; exit 1; fi
if [ -n "$1" ]; then SIMULATION="--simulation=$1"; fi

java -Xmx512m -XstartOnFirstThread -classpath \
lib/org.eclipse.swt.osx64.jar:\
Siafu.jar:\
lib/org.apache.commons.collections-3.2.1.jar:\
lib/org.apache.commons.configuration-1.6.0.jar:\
lib/org.apache.commons.lang-2.4.0.jar:\
lib/org.apache.commons.logging-1.1.1.jar \
de.nec.nle.siafu.control.Siafu $SIMULATION
Nam Ngo
  • 21
  • 3
  • 1
    Isn't the error message pretty clear? Start your GUI thread in the main thread and you are good. –  Sep 13 '11 at 01:56
  • Hi, that's why I'm confused, because I've specified the -XstartOnFirstThread in the launch script – Nam Ngo Sep 13 '11 at 03:26
  • 1
    Except that you're putting your `Display` initialization in a runnable that you've passed off to a `Thread`. `-XstartOnFirstThread` doesn't override this, it changes the behavior of the internal threading model. Do your `Display` initialization from the thread that calls `main()`. – Edward Thomson Sep 13 '11 at 15:41
  • Hi Ed, thanks a lot, I recheck the code and found that the Display init isn't called inside the main thread, the main thread create another thread and run the Display init. I modified it and ran successfully. – Nam Ngo Sep 19 '11 at 09:33

0 Answers0