title: Update SWT from out of thread, failed to execute runnable
body: <p>I've searched myself bloody for the answer to this, but none of the solutions that are explained neither on S/O nor anywhere else on the web seem to work.</p>
  
  <p>I've got two parts to my project. One part is the screen itself where SWT renders (and some basic eventhandling is done). The other part is a Network-class which handles server/client communication through sockets.</p>
  
  <p>What I'm currently doing is trying to allow a change of name in the program, so that when the client types "name Josh", it will set the name on the screen to Josh, updating a label that is created. This is where I'm stuck. I created a method called "updater" which will extend to more as time goes on, but right now only updates a label. I created this function inside of the GUI-class, and made it public to be called from the network-class. However, when it is called, I get an error saying that it failed to create that runnable, pointing to a Null pointer exception. I've tried <code>Display.getCurrent();</code>, <code>Display.getDefault();</code> and <code>UIPlatform.getWorkBench().getDisplay()</code>, but none of them seem to work.</p>
  
  <p><strong>Updater method (in GUI class)</strong></p>
  
  <pre><code>public static void updater(String arg)
  {
      Display.getDefault().asyncExec(new Runnable()
      {
          public void run()
          {
              if(!lblPlayer2.getText().equals(arg)) { lblPlayer2.setText(arg); }
          }
      });
  }
  </code></pre>
  
  <p><strong>Call to updater method (from Network-class)</strong></p>
  
  <p><code>IntroScreen.updater(split[1]);</code></p>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
  at org.eclipse.swt.SWT.error(Unknown Source)
  at org.eclipse.swt.SWT.error(Unknown Source)
  at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
  at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
  at client.IntroScreen.open(IntroScreen.java:44)
  at client.IntroScreen.main(IntroScreen.java:29) Caused by: java.lang.NullPointerException
  at client.IntroScreen$2.run(IntroScreen.java:155)
  at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source)
  ... 5 more
  </code></pre>
  
  <p><strong>Full source for GUI:</strong> <a href="http://hastebin.com/abolederul.java" rel="nofollow">http://hastebin.com/abolederul.java</a></p>
  
  <p><strong>Full source for Network:</strong> <a href="http://hastebin.com/ipulirifat.java" rel="nofollow">http://hastebin.com/ipulirifat.java</a></p>
  
  <p>I've hit a brick wall here. Does anyone have a clue to why this is occuring, and if you do, I'd love it if you could explain how I should be thinking to prevent errors like this going forward.</p>