How To Fix Java.Lang.NoClassDefFoundError: Javax/xml/bind/annotation/xmlschema When Install Android SDK

When i install android sdk use android skd manager, i meet an Java.Lang.NoClassDefFoundError error like below. The error message said that javax.xml.bind.annotation.XmlSchema class can not be found. I struggle for some time, and finally find the method to fix it.

$ ./sdkmanager
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
  at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
  at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
  at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
  at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
  at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
  ... 5 more

1. How To Fix javax.xml.bind.annotation.XmlSchema Class Can Not Be Found Error.

The reason for this error is because the jdk version that is used is not correct. So first you need to find out which java version areĀ  you using.

  1. Open a terminal and run $ java -version command like below.
    $ java -version
    java version "12.0.1" 2019-04-16
    Java(TM) SE Runtime Environment (build 12.0.1+12)
    Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
  2. My java version is 12.0.1, this java version will cause this error, so i need to install another java version such as java 8 and then set java 8 as my default java jdk.You can read article How To Install / Uninstall Multiple Java Versions In Mac OS By Home Brew Or Manually to learn more.
  3. When you install java 8 successfully, run the command ./sdkmanager in terminal again, then the error will be disappeared.
READ :   How To Parse Java Source Code Use JDK Parser

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.