3

I am getting Error: java.lang.ClassNotFoundException whenever Android tries to inflate TabLayout in my Fragment. I am using Kotlin, not sure if that matters or not.

My Fragment Layout

<LinearLayout android:layout_height="match_parent"
          android:layout_width="match_parent"
          android:orientation="vertical"
          xmlns:android="http://schemas.android.com/apk/res/android">

<!-- our tablayout to display tabs  -->
<android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"/>

My Gradle Dependencies

def room_version = "2.1.0-alpha04"

implementation "androidx.room:room-runtime:$room_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor "androidx.room:room-compiler:$room_version"
// For Kotlin use kapt instead of annotationProcessor

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha02'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support:design:28.0.0'

and I am getting this error

2019-03-07 10:05:12.020 29278-29278/com.nandrezholdingslimited.pebblar E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nandrezholdingslimited.pebblar, PID: 29278
android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.design.widget.TabLayout
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.design.widget.TabLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TabLayout" on path: DexPathList[[zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/base.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_resources_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.nandrezholdingslimited.pebblar-ZCiGV8uuN3ooM7_JoASOUg==/lib/arm64, /system/lib64, /system/vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at com.nandrezholdingslimited.pebblar.features.tripslist.TripsListFragment.onCreateView(TripsListFragment.kt:30)

I have read from various stackoverflow posts that it might be because of library version incompatibilities issues, but I have tried many different versions and I am still getting this crash whenever Android tries to inflate TabLayout into the Fragment.

Please help me with this issue.

thank you!

5
  • are you sure there is no file of your project in .zip folder? Commented Mar 7, 2019 at 2:41
  • hi @Faisal, sorry i did not get what you meant by "no file of your project in .zip folder" Commented Mar 7, 2019 at 2:53
  • As your error message said: Didn't find class "android.support.design.widget.TabLayout DexPathList[[zip file "bla bla bla"....... Commented Mar 7, 2019 at 3:02
  • I created another sample project placing TabLayout inside a fragment, no crash with this project If I look at app -> build -> outputs -> logs -> manifest-merger-debug-report.txt by searching keyword com.android.support:design:28.0.0 I was able to find some entries. But for the project that crashes, i wasn't able to find com.android.support:design:28.0.0 in manifest-merger-debug-report.txt Commented Mar 7, 2019 at 3:07
  • I was able to dig into the problem further If i create a new project using Android Studio & tick "Use AndroidX artifacts" and add implementation 'com.android.support:design:28.0.0', manifest-merger-debug-report.txt WON'T show the design library been merged. If i DO NOT tick Use AndroidX artifacts, manifest-merger-debug-report.txt WILL show the design library been merged. Commented Mar 7, 2019 at 3:45

1 Answer 1

6

OK I know what the problem is.

If I choose "Use AndroidX artifacts" while creating a new project, then I'll have to use

implementation 'com.google.android.material:material:1.1.0-alpha04'

and

com.google.android.material.tabs.TabLayout

If I use

implementation 'com.android.support:design:28.0.0'

and

android.support.design.widget.TabLayout

the app will crash during inflating TabLayout.

Whereas if I did not choose "Use AndroidX artifact", I can use 'com.android.support:design:28.0.0' without any problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.