19

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 :)

3dDi92
  • 227
  • 3
  • 4
  • 9

5 Answers5

23

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.

Community
  • 1
  • 1
alang6d2
  • 231
  • 1
  • 2
  • 2
    Thanks for the tip, but I already tried it some days ago and because I read a similar post where someone recommended to do the `Invalidate Caches and Restart`. This didn’t solve the problem for me but thanks again for the efforts. – 3dDi92 Jan 07 '15 at 08:59
  • problem Solved . Thanks, – Chirag Savsani Jul 23 '16 at 14:43
  • Almost worked for me: I first had to delete the build directory in the project. After that "File > Invalidate Caches / Restart" and after that sync. Then the problem dissapeared. – MartijndeM Aug 25 '18 at 10:05
1

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

Mushir
  • 1,263
  • 9
  • 12
1

Just clean the project. It worked for me.

VP.
  • 15,509
  • 17
  • 91
  • 161
smoothumut
  • 3,423
  • 1
  • 25
  • 35
0

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.

Whales
  • 388
  • 1
  • 3
  • 10
  • Thanks for the tip, but when I reinstalled the Android Studio I also reinstalled the entire Android SDK Kit. This did not solve my problem, but thanks again. – 3dDi92 Jan 07 '15 at 08:51
  • @3dDi92 I think v1.02 doesnt include the SDK tools, it is probably using the SDK tools of your previous installation. You can download the stand-alone SDK tools here http://developer.android.com/sdk/index.html#Other – Whales Jan 07 '15 at 12:15
  • I reinstalled the SDK Tool Kit – 3dDi92 Jan 07 '15 at 15:36
  • You still have the same problem @3dDi92? – Whales Jan 09 '15 at 10:08
  • Having the same problem as @3dDi92 with each and every dependency. Anyone knows a fix? – Levente Kürti Jan 09 '15 at 11:50
0

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.

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
slellis
  • 3,693
  • 1
  • 12
  • 11