23
votes

I am beginner in android now.I am not able to resolve this error in android studio. Whenever I run my application this error occur. How do I fix it Error: Unable to load class'javax.xml.bind.JAXBException' Possible causes for this unexpected error include:

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) [enter image description here][1]may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project. In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

7

7 Answers

19
votes

this is my solution

update gradle build tool version in project level gradle

dependencies {
    classpath 'com.android.tools.build:gradle:4.2.0'
}

and then Android Studio will download and change your gradle-wrapper.properties file

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

Sync project, everything is OK.

14
votes

My problem was resolved when I changed the JDK for each of my Android SDKs:

Project Structure -> Platform Settings\SDKs -> Android API xx Platform -> Change "Java SDK" to 1.8

This resolved the problem;

Also change that the Project SDK to 1.8.

enter image description here enter image description here

If the problem is not resolved, Please try to run IDE under JDK 8.

7
votes

Also you can Update your gradle version in project level gradle

classpath 'com.android.tools.build:gradle:4.x.x'

and fixed this issue.

6
votes

This might be too late but maybe some one needs to know the reason:

If you updated android studio to v4.2 and this happened, its because it is build in java 11

You have two options:

  1. change JDK path manually in: Project Structure -> SDK Location

  2. you should update your gradle setting use these two versions or above them:

classpath 'com.android.tools.build:gradle:4.0.0' distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip

I hope i could save some one's time

0
votes

install java 8, and set your JDK path with java 8

File- > Project structure. -> SDK location -> JDK Location

for mac os:

/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
0
votes

First check your gradle-wrapper.properties distributionUrl value and update with latest version of gradle.

distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

enter image description here

0
votes

this is the one of the possible solutions, It was worked for me.

In app build file, add the options javaCompileOptions{ ... }

android {
    …
    defaultConfig {
    …
        //add this options
        javaCompileOptions { 
            annotationProcessorOptions { 
                includeCompileClasspath = true 
            } 
        }
    }
    …
}