0

Have a project at hand that uses the SWT framework. Unfortunately, am currently encountering this problem which I really don't know how to solve it, got any insights why I'm encountering this issue?

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
    at org.eclipse.swt.SWT.error(SWT.java:4397)
    at org.eclipse.swt.SWT.error(SWT.java:4312)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3976)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3653)
    ... 4 more
Caused by: java.lang.NullPointerException
    at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2126)
    at org.eclipse.swt.graphics.GC.<init>(GC.java:171)
    at org.eclipse.swt.graphics.GC.<init>(GC.java:134)
    at org.eclipse.swt.widgets.Tree.setScrollWidth(Tree.java:2951)
    at org.eclipse.swt.widgets.Tree.setScrollWidth(Tree.java:2944)
    at org.eclipse.swt.widgets.Tree.removeAll(Tree.java:2392)
    ... <internal code>
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    ... 6 more

My apologies for hiding <internal code>, the project is confidential. Tried to make a snippet to replicate it, can't seem to replicate it well.

This stacktrace line org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138) is pertaining to this maven dependency:

  • GroupId: org.eclipse.swt
  • ArtifactId: org.eclipse.swt.cocoa.macosx
  • Version: 4.2.1
David B
  • 2,725
  • 11
  • 44
  • 76
  • Googling for "swt nullpointerexception Control.internal_new_GC" shows up bug reports. So, a SWT-bug could be the problem. – mm759 Nov 15 '16 at 07:40
  • 2
    4.2.1 is quite an old version of SWT, 4.6.1 is current. We really need to see a [mcve] – greg-449 Nov 15 '16 at 10:57
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Robert Longson May 21 '19 at 06:39

1 Answers1

1

You may encounter this error when the parent in Runnable is null (not assigned), so checking if any parameter is null may solve the problem.

Display.getDefault().syncExec(new Runnable() {
    public void run() {
        parent.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent event) {
                dispose();
            }
        });
    }
});
Samuel Liew
  • 68,352
  • 105
  • 140
  • 225
Lost
  • 11
  • 3