Why cmd give error when we open uiautomatorviewer?
Set your all android path properly.
Add variable in system environment as mention below.
ANDROID_SWT : C:\Users\chetan\AppData\Local\Android\Sdk\tools\lib\x86_64
ANDROID_HOME : C:\Users\chetan\AppData\Local\Android\Sdk
ANDROID_PLATFORM_TOOLS : C:\Users\chetan\AppData\Local\Android\Sdk\platform-tools
Add below mention Path in Path Variable in system environment.
C:\Program Files\Java\jdk\bin;
C:\Users\chetan\AppData\Local\Android\Sdk\tools\bin;
C:\Users\chetan\AppData\Local\Android\Sdk\tools;
C:\Users\chetan\AppData\Local\Android\Sdk\platform-tools;
C:\Program Files\nodejs\node_modules\npm\bin;
C:\Users\chetan\AppData\Local\Android\Sdk;
C:\Users\chetan\AppData\Local\Android\Sdk\tools\lib\x86_64\swt.jar;
Pre-Check - Verify the java Version installed in your system.
VERIFY - java -version
java version "1.8.0_221" Java(TM) SE Runtime Environment (build 1.8.0_221-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
If this message appears that means you have JAVA 8 install and uiautomatorviewer only supports till JAVA 8.
So install JAVA 8 from here and if you already have JAVA install down grade it to JAVA 8