【问题标题】:Importing RecyclerView not working even WITH import statement即使 WITH import 语句导入 RecyclerView 也不起作用
【发布时间】:2020-10-09 01:57:20
【问题描述】:

我遇到了一个问题,我将现有 Android Studio 项目中的一些文件复制粘贴到了一个新项目中。

我复制粘贴的项目使用 RecyclerView(并通过 import androidx.recyclerview.widget.RecyclerView; 导入它,并且在该项目中完美运行。

但是,我的新项目中的同一行考试给出了 Cannot resolve symbol 'recyclerview' 错误。

我不知道我能做些什么来解决这个问题。我尝试过使缓存无效并重新启动,但这并没有解决任何问题。我已经看到有关此主题的其他问题,但他们都忘记添加导入语句。就我而言,我有一个运行良好的项目,但是一旦复制到我的新项目中,那行代码就无法正常工作。

【问题讨论】:

    标签: android android-studio debugging android-recyclerview


    【解决方案1】:

    您很可能缺少依赖项:

    dependencies {
        implementation "androidx.recyclerview:recyclerview:1.1.0"
        // For control over item selection of both touch and mouse driven selection
        // implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc03"
    }
    

    【讨论】:

    • 我在哪里添加这个?在我的 Build.gradle 文件中?
    • 是的,在模块级别,而不是根项目。
    • 谢谢你,解决了。 Gradle 似乎没有为粘贴的代码添加该依赖项。
    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多