java – Android Studio 1.0.2 new project – Cannot resolve symbol 'ActionBarActivity'-ThrowExceptions

Exception or error:

I’m very confused. Today I just reinstalled Android Studio Version 1.0.2 (and the Android SDK) because I had some problems yesterday when I created a new project. I hoped that I could solve them by just reinstall everything, but actually the problem still exists and I don’t know how to solve it.

After I created a new project in Android Studio and switch to my MainActivity (I didn’t changed anything in one of the files), I always get the following errors displayed in the file.

MainActivity.class:

package com.android.testapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Errors:

  • Cannot resolve symbol ‘ActionBarActivity’
  • Cannot resolve method ‘onCreate(android.os.Bundle)’
  • Cannot resolve method ‘setContentView(int)’
  • Cannot resolve method ‘getMenuInflater()’
  • Cannot resolve method ‘setContentView(int)’
  • Cannot resolve method ‘onOptionsItemSelected(android.view.MenuItem)’

Project: build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Module: build.gradle

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

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

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

I already rebuild and cleaned my project and 'Sync Project with Gradle Files' but none of them fixed my issues.

The funny thing is, that I can compile and run my project on my smartphone…

PS: I guess it seems to be a gradle issue, because whenever I add a new library such as 'com.google.android.gms:play-services:6.5.87' and then try to import it 'import com.google.android.gms.gcm.GoogleCloudMessaging;'. I also get the 'Cannot resolve symbol…' error displayed. I didn’t complied it with the GCM Service…

Thanks for your help in advance 🙂

How to solve:

For everyone who needs it, you can find it here:

Android Studio says "cannot resolve symbol" but project compiles

If the link goes down:

File > Invalidate Caches / Restart... and Invalidate and Restart to solve the issue.

###

Try
(Build -> Rebuild project and then Build-> Clean project) if this not work try below procedure

Please Click on File -> Invalidate Caches/Restart.. tab
This will resolve this

###

Just clean the project. It worked for me.

###

Ill suggest that you download a fresh version of Android SDK Tools.
It is possible that one (or more) of your build tools, platform may be corrupt.
And point your Android Studio to the new sdk tools.

This fixed the error for me.

###

This problem arise after I installed the Android SDK Build-tools version 21.1.2. So I went back to the 21.1.1 version and the problem was solved.

Leave a Reply

Your email address will not be published. Required fields are marked *