Lizzzz90
Lizzzz90

Reputation: 125

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

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.

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

As you can see in the attached Image the 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.

Upvotes: 7

Views: 15114

Answers (6)

Rida Rezzag
Rida Rezzag

Reputation: 3953

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

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

Upvotes: 1

ChamTT
ChamTT

Reputation: 41

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

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

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

Upvotes: 3

user7650463
user7650463

Reputation: 1

had the same problem. try to insert

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.

Upvotes: 0

onDroid
onDroid

Reputation: 471

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

Tried it on Android Studio version 1.5.1 with minSDKVersion 17.

Upvotes: 1

rhodo
rhodo

Reputation: 188

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

My module's build.gradle file looked like this:

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.

Upvotes: 7

HellCat2405
HellCat2405

Reputation: 762

Did you sync your project?

enter image description here

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

Upvotes: 1

Related Questions