【问题标题】:Unresolved reference : recyclerView未解决的参考:recyclerView
【发布时间】:2021-12-28 11:59:03
【问题描述】:

我正在关注本教程RecyclerView in Android Studio Tutorial 并面临 Unresolved reference : recyclerview 错误。 我认为 gradle 文件中存在一些问题,但我无法解决。请帮助。 下面给出了完整的 gradle 文件以及 xml 代码的链接xml code

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 30

    defaultConfig {
        applicationId "com.example.newsapp"
        minSdk 21
        targetSdk 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

【问题讨论】:

  • 请不要将代码作为图像包含在内,只需将其作为文本包含在此处即可。该示例很可能使用合成导入,因此只需使用 findViewById
  • @a_local_nobody 我在 recyclerView.layoutManager = LinearLayoutManager(this) 中有错误
  • 这没有多大帮助,您能否编辑您的问题以包含相关代码?

标签: android kotlin android-recyclerview


【解决方案1】:

教程已过时。它使用合成材料,已弃用且不能再使用。在此处阅读有关从合成迁移的更多信息,或尝试查找更新的教程:

Migrate from Kotlin synthetics to Jetpack view binding

【讨论】:

    猜你喜欢
    • 2020-04-18
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    • 2021-08-17
    • 2016-12-14
    • 2020-05-27
    相关资源
    最近更新 更多