24

Unable to load class 'javax.xml.bind.JAXBException'.

spent much time for this error but I don't get it , what's wrong with my code in android studio , when I run app

**Execution failed for task ':app:compileDebugJavaWithJavac'.

javax/xml/bind/JAXBException**

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Didier Supernover
  • 567
  • 2
  • 7
  • 21
  • 1
    You are using a gradle plugin developed for Java 8 but your used Java version is higher. The java.xml.bind package was disabled in Java9+10 and removed in Java11. The easiest was would be to switch the project to a Java 8 JDK in project settings. – Robert Feb 13 '21 at 19:03
  • sounds good , but how to switch from 11 to 8 Java in Android studio thanks ? – Didier Supernover Feb 13 '21 at 19:07
  • did you found any solution to this? – Suraj Giri May 06 '21 at 01:22

6 Answers6

46

I too faced the same issue when I updated my Android Studio to V4.2. I had to modify two files.

In build.gradle, I changed dependency from

classpath 'com.android.tools.build:gradle:3.6.3'

to

classpath 'com.android.tools.build:gradle:4.0.0'

In gradle-wrapper.properties, I changed the distributionUrl from

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

to

   distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Ganesh S S
  • 571
  • 5
  • 10
11

I had the same problem and I solved it by changing the Android JDK path by JDK 8.

First you need to download and install JDK 8 from this link [JDK 8] (https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)

and should change your JDK path manually: Go to Project Structure -> SDK Location -> JDK Location -> select the three dots button -> select the JDK 8 folder installed in your pc (generally it will be in C:\Program Files\Java\jdk1.8.. ) press ok. it solved this problem for me.

  • 2
    You are the real life-saver! THIS should be the accepted answer since updating gradle and AGP isn't always the way to go for some projects... – Tharkius Jul 09 '21 at 14:12
2

I too faced this issue and this helped me to rectify. In build.grade, change the classpath to

classpath com.android.tools.build:gradle:4.0.0

In gradle-wrapper.properties, change the distributionUrl

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Pritesh Patel
  • 678
  • 17
  • 35
Ramya Bm
  • 27
  • 2
1

this is because your Android Studio was upgraded to 4.2, and in 4.2 the AS is build in java 11, you should change your JDK path manually, Project Structure -> SDK Location, don't use your Android Studio.app's JDK path. install or change another one.

T.Smith
  • 101
  • 1
  • 4
1

I had the same problem and I solved it by updating "DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'"

android {

    buildFeatures {

         dataBinding true

         // for view binding:
         // viewBinding true
    }
}

Reference DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'

Zain
  • 37,492
  • 7
  • 60
  • 84
0

I simply upgraded Gradle and it worked

Lucas
  • 458
  • 4
  • 6