I’m trying to run uiautomatorviewer on Big Sur and I’m getting this error

java.lang.NullPointerException
    at org.eclipse.swt.widgets.Control.internal_new_GC(Unknown Source)
    at org.eclipse.swt.graphics.GC.<init>(Unknown Source)
    at org.eclipse.swt.graphics.GC.<init>(Unknown Source)
    at org.eclipse.swt.widgets.Tree.computeSize(Unknown Source)
    at org.eclipse.swt.layout.GridData.computeSize(Unknown Source)
    at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
    at org.eclipse.swt.layout.GridLayout.computeSize(Unknown Source)
    at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
    at org.eclipse.swt.custom.SashFormLayout.computeSize(Unknown Source)
    at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
    at org.eclipse.swt.custom.SashFormLayout.computeSize(Unknown Source)
    at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
    at org.eclipse.swt.layout.FillData.computeSize(Unknown Source)
    at org.eclipse.swt.layout.FillLayout.computeChildSize(Unknown Source)
    at org.eclipse.swt.layout.FillLayout.computeSize(Unknown Source)
    at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
    at org.eclipse.swt.layout.GridData.computeSize(Unknown Source)
    at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
    at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
    at org.eclipse.swt.widgets.Composite.updateLayout(Unknown Source)
    at org.eclipse.swt.widgets.Composite.updateLayout(Unknown Source)
    at org.eclipse.swt.widgets.Composite.layout(Unknown Source)
    at org.eclipse.swt.widgets.Display.runSettings(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:78)

4

This question appears to be the same issue that you were seeing. I followed this answer, which was to download the latest SWT Binary and Source release from the Eclipse Project, extract it, rename swt.jar to swt2.jar, and copy it to ~/Library/Android/sdk/tools/lib/x86_64/swt2.jar.

This workaround was originally suggested in this issue report. One person said they also had to copy it to ~/Library/Android/sdk/tools/lib/x86/swt2.jarbut I did need to do that.

In my case, I downloaded the 4.19 Mac OSX (64 bit version) release for my (non-ARM) MacBook Pro. You can find other releases on the Eclipse Project Downloads page.