Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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.

like image 202
Lizzzz90 Avatar asked Oct 12 '15 10:10

Lizzzz90


3 Answers

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.

like image 78
rhodo Avatar answered Nov 08 '22 08:11

rhodo


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

like image 36
ChamTT Avatar answered Nov 08 '22 06:11

ChamTT


Did you sync your project?

enter image description here

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

like image 45
HellCat2405 Avatar answered Nov 08 '22 08:11

HellCat2405