java - 如何修复Android Studio中的 "Missing classes"错误?

标签 java android xml

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

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'
}

最佳答案

您混淆了 AndroidX 依赖项与 AppCompat。要么从 Refactor -> Migrate to AndroidX 迁移到 AndroidX,要么使用 AppCompat。

正如在您的代码中一样,您已使用约束布局的两个依赖项。解决您的问题的最简单的解决方案是删除该行

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

关于java - 如何修复Android Studio中的 "Missing classes"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57511034/

相关文章:

java.lang.OutOfMemory错误: Java heap space while reading Excel file into java bean using XLSReader

android - 我的项目在构建变体文件夹中找不到google-services.json

android - 如何将 Github 中的库导入 Android Studio

php - 从 xml 变量中过滤掉撇号

xml - 如何使用 awk 解析逗号分隔值 (csv)?

ruby-on-rails - Nokogiri XML 文件输出位于何处?

java - TextView 中的文本对齐方式

java - 缺少字符串类型的方法参数的 URI 模板变量

java - Eclipse Plugin Dev - 在编辑文件时创建和更新自定义标记

Android AlarmManager 和服务问题