Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalid Thread Access even with XstartOnFirstThread in vm args
    text
    copied!<p>I have an embryonic Java Web Start application with a single class. It runs on Windows and Linux but gets the dreaded Invalid Thread Access error on Mac OS X. I realise that this has been dealt with elsewhere. I have spent two full days scouring the Internet and have implemented all the solutions, but the problem persists.</p> <p>My understanding is that calls to SWT must be made from the main thread which is the case here. Correct me if I am wrong in that.</p> <p>I will post 3 snippets below, the source code of the application, the relevant part of the jnlp file and the error message on the Mac. The question is at the end.</p> <hr> <p>JAVA SOURCE CODE</p> <pre><code>package client; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class AccountWindow { public static void main(String[] args) { Display display = new Display(); **// error occurs here** Shell shell = new Shell(display); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } </code></pre> <hr> <p>JNLP SNIPPET</p> <pre><code>&lt;resources os="Mac\ OS\ X" arch="x86_64"&gt; &lt;j2se version="1.5+" java-vm-args="-XstartOnFirstThread" /&gt; &lt;nativelib href="swt-4.2-cocoa-macosx-x86_64.jar" /&gt; &lt;/resources&gt; </code></pre> <hr> <p>ERROR MESSAGE</p> <pre><code>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.&lt;init&gt;(Unknown Source) at org.eclipse.swt.widgets.Display.&lt;init&gt;(Unknown Source) at org.eclipse.swt.widgets.Display.&lt;init&gt;(Unknown Source) at client.AccountWindow.main(AccountWindow.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.javaws.Launcher.executeApplication(Launcher.java:1550) at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1488) at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1299) at com.sun.javaws.Launcher.run(Launcher.java:114) at java.lang.Thread.run(Thread.java:637) </code></pre> <hr> <p>PLEASE NOTE<br/> - The display.syncExec solution posted at <a href="http://www.eclipse.org/swt/faq.php#javawebstart" rel="nofollow">http://www.eclipse.org/swt/faq.php#javawebstart</a> is not applicable because before you can invoke it you need a display. The error here happens when I try to create the display.<br/> - I have used JaNeLa to validate the jnlp file and there are no red errors.<br/> - &LT;resources os="Mac\ OS\ X" arch="i386"&GT; is being correctly interpreted because the correct swt library is being loaded.<br/> - You can reproduce the error at <a href="http://thelinkjuicer.com/gannonline/client.jnlp" rel="nofollow">http://thelinkjuicer.com/gannonline/client.jnlp</a><br/></p> <hr> <p>AND NOW THE QUESTION<br/> Can anyone see anything in the source code or the jnlp snippet that would cause the error?<br/> Secondary question: how can you tell if the -XstartOnFirstThread argument is actually being read by the VM?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload