java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path
Asked Answered
A

5

10

I just migrated my project to androidx and i am getting an inflation error for inflating viewpager component...I replaced android.support.v4.view.ViewPager with androidx.viewpager.widget.ViewPager

This my xml file

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:padding="@dimen/_1dp"
      android:layout_height="wrap_content"
      android:background="@color/banner_border_color">

      <androidx.viewpager.widget.ViewPager
           android:id="@+id/vp_slider"
           android:layout_width="match_parent"
           android:layout_height="@dimen/_140dp"
           android:background="@drawable/thumb_new_background" />

           <RelativeLayout
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="bottom">

               <TextView
                   android:id="@+id/tv_banner_view_more"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_centerVertical="true"
                   android:layout_marginLeft="@dimen/_16dp"
                   android:background="@drawable/drawable_btn_curved"
                   android:paddingBottom="@dimen/_6dp"
                   android:paddingLeft="@dimen/_8dp"
                   android:paddingRight="@dimen/_8dp"
                   android:paddingTop="@dimen/_6dp"
                   android:visibility="gone"
                   android:text="@string/text_view_more"
                   android:textColor="@color/c_white"
                   android:textSize="@dimen/_8sp" />

     </RelativeLayout>

</FrameLayout>

The Error i'm getting :

Caused by: android.view.InflateException: Binary XML file line #329: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
         Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
         Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path: DexPathList[
Auditorium answered 16/7, 2019 at 5:59 Comment(6)
look like the error is in different xml file, search whole your project about androidx.core.view.ViewPager. if you don't find any place use androidx.core.view.ViewPager, then just need to clean projectEndermic
post your app build.gradle file. Hope you have not included it in any aar libraryPolly
Have u added below implementation 'com.google.android.material:material:1.1.0-alpha06' dependencies in your build.gradle` fileRehnberg
@SantanuSur yes my project have external aar fileAuditorium
@NileshRathod no this dependency not addedAuditorium
@Auditorium you need to add that dependencies in your build.gradle fileRehnberg
R
6

You need to below dependencies in your build.gradle file

implementation 'com.google.android.material:material:1.1.0
Rehnberg answered 16/7, 2019 at 6:2 Comment(4)
alpha08 is lattes avilable or need to stick with 06?Auditorium
@Auditorium it's your choice if you want to use alpha08 or alpha06 I'm currently using alpha06Rehnberg
app still crashing after adding dependency :(Auditorium
@Auditorium can u share latest crash log with question after adding these dependenciesRehnberg
A
38

I figure out problem, When we merger to androidx then android studio convert viewpager, swipe to refresh layout and some other views to androidx.core for example viewpager its looks like androidx.core.view.ViewPager but correct is androidx.viewpager.widget.ViewPager please check in your xml layouts and see there is right component is added or not if there is androidx.core then check for right one and replace it. And also import dependency

implementation 'com.google.android.material:material:1.1.0-alpha08
Auditorium answered 18/7, 2019 at 4:54 Comment(1)
@Auditorium Thanks a ton. for the catch in the XML layoutShanta
R
6

You need to below dependencies in your build.gradle file

implementation 'com.google.android.material:material:1.1.0
Rehnberg answered 16/7, 2019 at 6:2 Comment(4)
alpha08 is lattes avilable or need to stick with 06?Auditorium
@Auditorium it's your choice if you want to use alpha08 or alpha06 I'm currently using alpha06Rehnberg
app still crashing after adding dependency :(Auditorium
@Auditorium can u share latest crash log with question after adding these dependenciesRehnberg
B
1

You need to add below dependencies in your build.gradle file

implementation 'com.google.android.material:material:1.4.0
Bacciferous answered 20/9, 2021 at 10:2 Comment(0)
S
0

I think you need to Invalidate caches and restart

Go to File > Invalidate caches/Restart > ** Invalidate

Then rebuild project

Sama answered 17/7, 2019 at 1:10 Comment(0)
B
0

Upgrade build.gradle and gradle wrapper version

     classpath 'com.android.tools.build:gradle:4.2.1'
     distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Bulwark answered 12/4, 2023 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.