java Android Studio v7-少数类的导入错误(无法解析符号)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33078939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:09:06  来源:igfitidea点击:

Android Studio v7- Import errors for few classes (Cannot resolve symbol)

javaandroid

提问by Lizzzz90

I am a beginner to Android Programming. I am trying to create a basic Hello World App using Android Studio. I am getting following errors in Java File immediately after following the initial steps to create the Hello World Program.

我是 Android 编程的初学者。我正在尝试使用 Android Studio 创建一个基本的 Hello World 应用程序。按照创建 Hello World 程序的初始步骤后,我立即在 Java 文件中遇到以下错误。

"Cannot resolve Symbol FloatingActionButton"
"Cannot resolve Symbol Snackbar"
"Cannot resolve Symbol AppCompatActivity"
"Cannot resolve Symbol Toolbar"

As you can see in the attached Imagethe errors are in red. Please help me out here.

正如您在附加图片中看到的,错误是红色的。请帮帮我。

My build file content:

我的构建文件内容:

 defaultConfig {
        applicationId "com.example.helloworld.helloworld"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

Seems like I have added all the relevant dependencies.

好像我已经添加了所有相关的依赖项。

回答by rhodo

I had the same issue after inserting a new module with a blank activity into an existing project.

在将具有空白活动的新模块插入现有项目后,我遇到了同样的问题。

My module's build.gradlefile looked like this:

我的模块build.gradle文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.networkingtest"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
}

To resolve the issue I changed the versions of the appcompat and design dependencies from 23.1.0 to 23.0.1 (Note: this is the same version as in buildToolsVersion). Next I hit "Sync project with gradle files" followed by Build > Clean Project. After completion the project would run, but I changed the dependency versions back to 23.1.0, hit "Sync project with gradle files" followed by Build > Clean Project again. Now everything works.

为了解决这个问题,我将 appcompat 和设计依赖项的版本从 23.1.0 更改为 23.0.1(注意:这与 中的版本相同buildToolsVersion)。接下来我点击“Sync project with gradle files”,然后点击Build > Clean Project。完成后,项目将运行,但我将依赖项版本更改回 23.1.0,点击“同步项目与 gradle 文件”,然后再次点击 Build > Clean Project。现在一切正常。

回答by ChamTT

Include compile 'com.android.support:design:25.3.1'in build.gradle(Module:app)

包括compile 'com.android.support:design:25.3.1'build.gradle(Module:app)

Change the version 25.3.1to match your compile 'com.android.support:appcompat-v7:25.3.1'dependency

更改版本25.3.1以匹配您的compile 'com.android.support:appcompat-v7:25.3.1'依赖项

Import import android.support.design.widget.FloatingActionButton;in activity

导入import android.support.design.widget.FloatingActionButton;活动

回答by Ridha Rezzag

add the support:design in build.gradle: module app to dependencies this will fix it

将 build.gradle:module app 中的 support:design 添加到依赖项中,这将修复它

compile 'com.android.support:design:26.+'

回答by onDroid

I ran into the same issue when i created a project with an empty activity and further added a second activity which was of type Blank activity.

当我创建一个带有空活动的项目并进一步添加第二个活动类型为空白活动时,我遇到了同样的问题。

The steps which got me out was 1-Build->Clean Project 2-Sync Project with Gradle Files

让我退出的步骤是 1-Build-> Clean Project 2-Sync Project with Gradle Files

Tried it on Android Studio version 1.5.1 with minSDKVersion 17.

使用 minSDKVersion 17 在 Android Studio 1.5.1 版上尝试过。

回答by HellCat2405

Did you sync your project?

你同步你的项目了吗?

enter image description here

在此处输入图片说明

Also try deleting all "red" imports and re-import this classes.

还尝试删除所有“红色”导入并重新导入此类。

回答by user7650463

had the same problem. try to insert

有同样的问题。尝试插入

compile 'com.android.support:support-v4:25.2.0' compile 'com.android.support:design:25.2.0'

compile 'com.android.support:support-v4:25.2.0' compile 'com.android.support:design:25.2.0'

at the end of you buidl.gradle file.

在你的 buidl.gradle 文件的末尾。