android - 无法解析导入 android.support.v7.widget.RecyclerView;

标签 android android-studio android-recyclerview

我需要在 Android Studio 中创建一个 recyclerview。我不知道为什么它一直说它无法解析符号回收器 View 。我已经按照那些网站教程完成了所有步骤。

我的应用程序 gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.android.support:appcompat-v7:29.1.1'
    //card view
    implementation 'com.android.support:cardview-v7:29.1.1'
    //recyclerView
    implementation 'com.android.support:recyclerview-v7:29.1.1'
    //picasso library to retrive images
    implementation 'com.squareup.picasso:picasso:2.71828'


    implementation 'com.google.firebase:firebase-storage:18.0.0'

    implementation 'com.google.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    apply plugin: 'com.google.gms.google-services'

}

我可以知道我的 gradle 文件中的代码有什么问题吗?提前致谢。 这是我在 logcat 中的错误报告:

error

最佳答案

您正在尝试访问错误的包。

尝试 androidx.recyclerview 而不是旧版 android.support.v7.widget.RecyclerView;

您应该替换所有 com.android.support.* 依赖项,并替换为 androidx 等效项。 (目前,您混合了 androidx 和旧版 android.support 依赖项)

https://developer.android.com/jetpack/androidx/releases/recyclerview

您可以尝试使用 Android Studio 上的“重构”>“迁移到 AndroidX”选项进行自动修复

enter image description here

关于android - 无法解析导入 android.support.v7.widget.RecyclerView;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069737/

相关文章:

两种不同语言的android语言文件夹

android-studio - 无法解析 com.android.support.espresso :espresso-core:2. 2.2

android - android studio 调试时如何复制变量内值的文本?

java - Android - 无法实例化以下类

java - Recyclerview 里面的 Recyclerview ,获取父 Adapter 里面子行的点击位置

java - 如何从不同的 Activity 将开关布局添加到 RecyclerView?

android - 高程属性不工作android

android - SearchView 可以同时具有语音搜索按钮和键盘语音输入吗?

java - 库中的 Monodroid JNIEnv.FindClass

android - 如何在recyclerview中实现分页?