3
votes

Erreur de gonflage de la classe android.support.v7.widget.CardView ClassNotFoundException

J'essaye de gonfler une mise en page qui contient un CardView mais je suis confronté à quelques problèmes.

Ci-dessous est l'état d'erreur,

implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'

Kotlin code dans le RecyclerViewAdapter,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:card_view="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">
    <android.support.v7.widget.CardView
            android:id="@+id/cardView"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            card_view:cardCornerRadius="0dp"
            card_view:cardElevation="@dimen/margin10"
            card_view:cardMaxElevation="@dimen/margin10"
            card_view:contentPadding="@dimen/margin10">
        <RelativeLayout
                android:id="@+id/relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_gravity="center">
            <ImageView
                    android:id="@+id/iv_card_item"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:tint="@android:color/white"
                    android:padding="5dp"/>
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

Voici la mise en page xml.

class RecyclerViewAdapter(private val recyclerViewItems: ArrayList<HearthstoneCardItemData>, context: Context) :
    RecyclerView.Adapter<RecyclerViewHolder>() {

    private val inflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
        val view = inflater.inflate(R.layout.recycler_view_card_item, parent, false)
        return RecyclerViewHolder(view)
    }
}

J'ai également ajouté les bonnes dépendances dans le fichier gradle (je pense)

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hearthstonecards, PID: 14895
    android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class android.support.v7.widget.CardView
    Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.CardView
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.CardView" on path: DexPathList[[zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/base.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_resources_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.hearthstonecards-Kl_z5hCNi7YCycFhods3Tg==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        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.example.hearthstonecards.adapter.RecyclerViewAdapter.onCreateViewHolder(RecyclerViewAdapter.kt:34)
        at com.example.hearthstonecards.adapter.RecyclerViewAdapter.onCreateViewHolder(RecyclerViewAdapter.kt:15)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6942)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6114)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5997)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5993)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2227)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1558)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1518)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:613)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4029)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3746)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4299)
        at android.view.View.layout(View.java:20672)
        at android.view.ViewGroup.layout(ViewGroup.java:6194)

J'ai également nettoyé la reconstruction, toujours pas de changement Tout conseil serait apprécié!


3 commentaires

évidemment android.support.v7.widget.CardView ne vient pas de androidx


Cela ressemble à un problème androidx . Il a été déplacé ailleurs. Essayez à nouveau d'ajouter la vue de carte au XML sans spécifier le package, puis laissez-le compléter automatiquement le package.


@EpicPandaForce Vous avez raison, androidx n'a pas migré automatiquement le package xml cardview.


3 Réponses :


10
votes

Vous avez besoin de androidx.cardview.widget.CardView et non de android.support.v7.widget.CardView .


0 commentaires

1
votes

Le studio Android n'a pas complètement migré mon application vers Androidx. Mais après avoir changé le nom du package dans la mise en page xml, le problème a été résolu.

Merci à tous!


0 commentaires

2
votes

Lorsque j'ai migré vers androidx , mon Android Studio n'a pas complètement migré. Donc, le fait est que si vous migrez vers androidx , assurez-vous d'ajouter la dépendance CardView à votre build.gradle

build.gradle

<androidx.cardview.widget.CardView
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="200dp"
    android:layout_height="200dp"
    card_view:cardCornerRadius="4dp">

    <TextView
        android:id="@+id/info_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Text"/>
</androidx.cardview.widget.CardView>

et dans votre mise en page xml

dependencies {
    // Other dependencies ...
    implementation 'androidx.cardview:cardview:1.0.0'
}


0 commentaires