Java Can';不要再充气了
我将RecycleView添加到我的XML中,如下所示:Java Can';不要再充气了,java,inflate-exception,androidx,Java,Inflate Exception,Androidx,我将RecycleView添加到我的XML中,如下所示: <androidx.recyclerview android:id="@+id/recycleViewTest" android:layout_width="match_parent" android:layout_height="match_parent" /> dependencies { implementation fileTree(include: [
<androidx.recyclerview
android:id="@+id/recycleViewTest"
android:layout_width="match_parent"
android:layout_height="match_parent" />
dependencies
{
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "androidx.recyclerview:recyclerview:1.0.0-alpha1"
}
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:replace="android:appComponentFactory"
android:theme="@style/AppTheme">
该项目已编译,但在我运行它时崩溃,并出现以下异常:
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class androidx.recyclerview
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class androidx.recyclerview
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.recyclerview" on path: DexPathList[[zip file "/data/app/
我的compileSdkVersion设置为28。有什么建议吗
更新:
我在依赖项中添加了:
implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'
所以我的依赖项部分现在看起来像这样:
dependencies
{
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'
}
但现在我得到了一个新的错误:
Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0-alpha1] AndroidManifest.xml:22:18-86
is also present at [com.android.support:support-compat:28.0.0-beta01] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:6:5-21:19 to override.
要删除应用程序标记,请执行以下操作:
<androidx.recyclerview
android:id="@+id/recycleViewTest"
android:layout_width="match_parent"
android:layout_height="match_parent" />
dependencies
{
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation "androidx.recyclerview:recyclerview:1.0.0-alpha1"
}
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:replace="android:appComponentFactory"
android:theme="@style/AppTheme">
androidx.recyclerview是一个包名,您需要一个视图的包+类名来通过XML扩展它,我找过您,但是包androidx.recyclerview现在有了视图 如果您打算使用RecyclerView() 正确的gradle语句是:
implementation 'com.android.support:recyclerview-v7:27.1.1'
XML标记是:
android.support.v7.widget.RecyclerView
如果您切换到AndroidX,则需要进行更改
- 依赖于实现“androidx.recyclerview:recyclerview:1.0.0”
- XML布局文件标记到
androidx.recyclerview.widget.recyclerview
映射可以在“迁移到AndroidX”指南中找到。谢谢,稍后将尝试。奇怪的是,当我在xml中将“androidx.recyclerview”改为“androidx.recyclerview.widget.recyclerview”时,我所说的
androidx.recyclerview
是一个包,您需要查看它的全名。只是我注意到您尝试使用的库仍然是alpha,还没有准备好进行生产。试着使用旧的支架,直到它稳定。清楚,谢谢!我添加了您建议的库,但我有一个新的错误,请检查一下好吗?我更新了我的问题你必须删除另一个“androidx”它已经被删除了,我用我目前拥有的依赖列表更新了我的问题,谢谢!非常感谢。这应该是可以接受的答案,因为它正确地使用了AndroidX而不是appcompat-v7.xml标记应该是AndroidX.recyclerview.widget.recyclerview