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[
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 project Commented Jul 16, 2019 at 6:03
  • post your app build.gradle file. Hope you have not included it in any aar library Commented Jul 16, 2019 at 6:04
  • 1
    Have u added below implementation 'com.google.android.material:material:1.1.0-alpha06' dependencies in your build.gradle` file Commented Jul 16, 2019 at 6:05
  • @SantanuSur yes my project have external aar file Commented Jul 16, 2019 at 6:08
  • @NileshRathod no this dependency not added Commented Jul 16, 2019 at 6:10

5 Answers 5

39

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
Sign up to request clarification or add additional context in comments.

1 Comment

@dev_swat Thanks a ton. for the catch in the XML layout
6

You need to below dependencies in your build.gradle file

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

4 Comments

alpha08 is lattes avilable or need to stick with 06?
@dev_swat it's your choice if you want to use alpha08 or alpha06 I'm currently using alpha06
app still crashing after adding dependency :(
@dev_swat can u share latest crash log with question after adding these dependencies
1

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

implementation 'com.google.android.material:material:1.4.0

Comments

0

I think you need to Invalidate caches and restart

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

Then rebuild project

Comments

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

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.