Error Inflating Class and Android.Support.V7.Widget.Cardview

Error inflating class android.support.v7.widget.CardView

I solved this by adding updated cardview and appcompat on the app/build.gradle

dependencies {
...
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
}

Then rebuild the project

Error inflating android.support.v7.widget.CardView

At first add setContentView();

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) //missing
val recyclerView = findViewById(R.id.contactsView) as RecyclerView

Use Exact version App Level build.gradle

 dependencies {

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}

FYI

You are using very old versions. If you want to use latest then libraries will not work unless you make the following changes in your app:

  • Upgrade compileSdkVersion to 28 or later.
  • Update your app to use Jetpack (AndroidX).

AndroidX replaces the original support library APIs with packages in the androidx namespace. Read official guideline about AndroidX Overview.

Your Cardview & recyclerview will

 implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

Error inflating class android.support.v7.widget.CardView, recyclerView and SwipeRefreshLayout

Firstly

By now you should be aware that with the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack

Support Library version 28.0.0 is the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX. There is nothing like ...support:v29.0.0 so I doubt if your project will build successfully.

Secondly

You cannot mix both support and androidx libraries together in the same project, there will surely be conflicts unless you're using Jetpack tool. Migrate your support libraries to androidx using this Artifacts mapping

*And Finally**

References in an Androidx layout file should all be androidx artifacts and not otherwise.

Hence tag like this:

  <android.support.v7.widget.CardView
android:layout_width="match_parent

Should be:

    <androidx.cardview.widget.CardView
android:layout_width="match_parent

How to Resolve : Error inflating class android.support.v7.widget.CardView

You have implemented all dependencies in glide. Try below gradle

Gradle :

dependencies {
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation("com.github.bumptech.glide:glide:4.6.1") {
exclude group: "com.android.support"
}
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support:support-v4:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.android.support:recyclerview-v7:26.+'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.gms:google-services:3.1.0'
implementation 'com.android.support:design:26.+'
implementation 'de.hdodenhof:circleimageview:2.2.0'

implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
implementation 'com.android.support:gridlayout-v7:26.+'
implementation 'com.github.clans:fab:1.6.2'
testCompile 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'id.zelory:compressor:2.1.0'
implementation files('libs/libGoogleAnalyticsServices.jar')

apply plugin: 'com.google.gms.google-services'
}

Error inflating class androidx.cardview.widget.CardView on CardStackView library

delete the two lines marked here in the attached image** because these 2 lines included to the old appcompact support lib not included in androidx.appcompact and the view holder can't inflate because these 2 lines, I had the same problem and I tried to solve it by several ways change cardview to linear and makes it worked and after that tried to delete some lines from the card view and it works now perfectly

Use this:

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="@android:color/white">

instead of

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/selectableItemBackground"
android:foreground="?attr/selectableItemBackground"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="@android:color/white">

see the image i marked lines here

Error inflating class and android.support.v7.widget.CardView

I guess I can answer my own question.

Go to File -> Import -> Existing Android code into workspace --> Browse (Go to sdk/extras/android/support/v7/cardview) --> Click ok --> Click Finish

Your project explorer will now show cardview as a project.

Right click on cardview project --> Properties --> Android(Left Pane) --> Enable isLibrary (tick the checkbox) --> Apply --> ok

Now Right click on your project --> Properties --> Android(Left pane) --> Add (under library) --> cardview --> apply --> ok

Now right click on your project again --> build path --> configure build path --> Under projects tab, add cardview

You are done.

error while inflating class android.support.v7.widget.CardView

Try this it will help you
remove this android:foreground="?android:attr/selectableItemBackground"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardview"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="2dp"
card_view:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

....here i have a bunch of other layout elements
</RelativeLayout>
</android.support.v7.widget.CardView>

</LinearLayout>


Related Topics



Leave a reply



Submit