我是 java 的新手,但出于某種原因,嘗試創(chuàng)建一個應(yīng)用程序,該應(yīng)用程序在 android studio 中正確構(gòu)建,但是,當(dāng)嘗試在模擬器中打開時,它崩潰了。 這是我的完整代碼是應(yīng)用程序的壓縮包,我猜,主要錯誤是final View rootView = inflater.inflate(R.layout.fragment_sun, container, false);日志:錯誤2019-07-25 10:42:48.002 5383-5383/com.example.phocast E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.phocast, PID: 5383 android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.v7.widget.RecyclerView Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v7.widget.RecyclerView Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/base.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_resources_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.phocast-j1KYRRVBUGO2ddQzmNBB8w==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.phocast-在代碼的第 69 行SunFragment.java。我不明白 XML 中出了什么問題。對應(yīng)的 XML 為: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.RecyclerView android:id="@+id/rv_recycler_view" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" />有人可以檢查嗎?
3 回答

UYOU
TA貢獻1878條經(jīng)驗 獲得超4個贊
使用
androidx.recyclerview.widget.RecyclerView
在fragment_sun.xml
而不是
android.support.v7.widget.RecyclerView
因為在build.gradle中依賴是androidx.recyclerview:recyclerview:1.0.0
但是在SunFragment
RecyclerView 中是從導(dǎo)入的androidx

四季花海
TA貢獻1811條經(jīng)驗 獲得超5個贊
您正在使用androidx支持庫,因此請使用androidx.recyclerview.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView ????android:id="@+id/rv_recycler_view" ????android:scrollbars="vertical" ????android:layout_width="match_parent" ????android:layout_height="match_parent" ????xmlns:android="http://schemas.android.com/apk/res/android"?/>

慕蓋茨4494581
TA貢獻1850條經(jīng)驗 獲得超11個贊
以下屏幕截圖來自您的項目搜索結(jié)果:
android.support.v7
嘗試用相應(yīng)的androidx
包替換所有這些包
例如改變
android.support.v7.widget.RecyclerView
到
androidx.recyclerview.widget.RecyclerView
這是因為您的源代碼使用的是AndroidsX包,但您的 xml 布局使用android 支持包聲明是錯誤的。
添加回答
舉報
0/150
提交
取消