java - 如何修复 Android Studio 中的 'Cannot Resolve Symbol ' v7' 错误

标签 java android android-recyclerview

我正在尝试使用 android 支持的 recyclerView 小部件,虽然我已经将所有依赖项添加到我的 build.gradle 文件中(我认为),但行“import android.support.v7.widget.RecyclerView;”在我的 Activity 中没有解决。我是 Android Studio 的新手,所以我可能会遗漏一些非常基本的东西。

到目前为止,我已经尝试在项目构建 gradle 的所有项目以及我的模块构建 gradle 的所有项目中添加 google 存储库。我也改变了我的依赖关系并尝试更改版本号。我尝试使缓存无效并重新启动。我似乎确实能够导入“import androidx.recyclerview.widget.RecyclerView;”,但这与我所听到的不一样。

这是我的构建 gradle 文件:

//noinspection GradleCompatible
apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.example.chaos"
        minSdkVersion 20
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        customDebugType {
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    //implementation 'com.android.support:recyclerview-v7:28.0.0'

    implementation 'android.arch.persistence.room:runtime:1.1.1'
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
    androidTestImplementation 'android.arch.persistence.room:testing:1.1.1'

   // implementation 'com.android.support:support-v7'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
    androidTestImplementation ('androidx.test.espresso:espresso-core:3.2.0-alpha02', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

然后这是我在主要 Activity 中尝试的导入。看来我可以导入 android.support.v4 库,但 v7 甚至不是自动完成选项。非常感谢您的帮助!

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;

我希望导入行能够解析,因为它目前没有解析。

最佳答案

如果您使用的是 Android X,请尝试使用此依赖项

实现 'androidx.recyclerview:recyclerview:1.0.0'

关于java - 如何修复 Android Studio 中的 'Cannot Resolve Symbol ' v7' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55388847/

相关文章:

java - 无法在 UserRecyclerAdapter 类中使用 "custom_list_users.xml"来膨胀 fragment

java - 使用 Seekbar 将 imageView 旋转一定角度

java - 使用 Java 流从列表中的列表中平均特定值

java - HashMap 中的自动装箱返回 NULL

android - java.lang.IllegalArgumentException : width and height must be > 0 异常

android - Solrj 从 Android 索引文档

android - RecyclerView 分页时跳转到列表中间

java - 将通用列表转换为 java 对象

java - 天气应用程序 java.net.UnknownHostException

android - 在 Recyclerview 中拖动项目时自动滚动滚动条