CardViewを含むレイアウトを膨らませようとしていますが、いくつかの問題に対処しています。
ベローは状態であるエラーです、
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)
RecyclerViewAdapter内のKotlinコード、
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)
}
}
以下はxmlレイアウトです。
<?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>
また、gradleファイル内に適切な依存関係を追加しました(私は思います)
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'
再構築もクリーンアップしましたが、変更はありません。アドバイスをいただければ幸いです。
androidx.cardview.widget.CardView
ではなくAndroid.support.v7.widget.CardView
が必要です。
Android Studioは、アプリをandroidxに完全に移行しませんでした。しかし、xmlレイアウト内のパッケージ名を変更した後、問題が修正されました。
みんな、ありがとう!