猿问

如何修复 Android Studio 中的“缺少类”错误?

当我尝试在 Android Studio 中创建新活动时,会发生这些错误,在此错误之前我通常创建了一些活动(没有任何错误):


The following classes could not be found:

- android.support.constraint.ConstraintLayout (    Add constraint-layout library dependency to the project, Fix Build Path, Edit XML, Create Class)

- android.support.design.widget.CoordinatorLayout (Fix Build Path, Edit XML, Create Class)

- android.support.v7.widget.Toolbar (Fix Build Path, Edit XML, Create Class)

依赖库:



dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation 'androidx.appcompat:appcompat:1.0.2'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.android.support:support-v4:29.+'

    implementation 'com.android.support:design:29.+'

    implementation 'com.android.support:appcompat-v7:29.+'

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'androidx.test:runner:1.2.0'

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.google.android.material:material:1.0.0'

    implementation 'com.squareup.retrofit2:retrofit:2.0.2'

    implementation 'com.squareup.retrofit2:converter-gson:2.0.2'

    implementation 'com.squareup.picasso:picasso:2.5.2'

    implementation 'de.hdodenhof:circleimageview:3.0.0'

    implementation 'com.mikhaellopez:circularimageview:3.2.0'

    implementation 'com.google.android.gms:play-services-base:11.0.1'

    implementation 'com.google.android.gms:play-services-basement:11.0.1'

    implementation 'com.google.android.gms:play-services-safetynet:11.0.1'

    implementation 'com.google.android.gms:play-services-tasks:11.0.1'

}


当年话下
浏览 298回答 2
2回答

潇湘沐

看起来您正在尝试在同一个项目中使用 AndroidX 库和支持库。从菜单迁移到 AndroidX,它将替换包名称和依赖项。您的项目正在从支持库中添加小部件,而不是从导致此问题的 AndroidX 添加小部件。

喵喔喔

您已经将AndroidX依赖与AppCompat. 从 Refactor -> Migrate to AndroidX 将其迁移到 AndroidX 或使用 AppCompat。正如在您的代码中一样,您已经为Constraint Layout. 解决您问题的最简单方法是删除该行implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
随时随地看视频慕课网APP

相关分类

Java
我要回答