Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarActivity cannot resolve a symbol

In my android Studio, Compiler is not able to locate ActionBarActivity. Because of it, I am getting many errors. The compiler is not able to import the ActionBarActivity and ActionBar class. These are the lines where compiler is throwing error:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;

I tried to search on stackoverflow before asking a question. The answer i got is for the eclipse which is to add the library. I tried doing it in Android Studio, but didn't get anything.

like image 322
Sumit Avatar asked Jan 23 '14 18:01

Sumit


3 Answers

Follow the steps mentioned for using support ActionBar in Android Studio(0.4.2) :

Download the Android Support Repository from Android SDK Manager, SDK Manager icon will be available on Android Studio tool bar (or Tools -> Android -> SDK Manager).

enter image description here

After download you will find your Support repository here

$SDK_DIR\extras\android\m2repository\com\android\support\appcompat-v7

Open your main module's build.gradle file and add following dependency for using action bar in lower API level

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

Sync your project with gradle using the tiny Gradle icon available in toolbar (or Tools -> Android -> Sync Project With Gradle Files).

There is some issue going on with Android Studio 0.4.2 so check this as well if you face any issue while importing classes in code.

Import Google Play Services library in Android Studio

If Required follow the steps as well :

  • Exit Android Studio
  • Delete all the .iml files and files inside .idea folder from your project
  • Relaunch Android Studio and wait till the project synced completely with gradle. If it shows an error in Event Log with import option click on Import Project.

This is bug in Android Studio 0.4.2 and fixed for Android Studio 0.4.3 release.

like image 150
Piyush Agarwal Avatar answered Nov 12 '22 07:11

Piyush Agarwal


If the same error occurs in ADT/Eclipse

Add Action Bar Sherlock library in your project.

Now, to remove the "import The import android.support.v7 cannot be resolved" error download a jar file named as android-support-v7-appcompat.jar and add it in your project lib folder.

This will surely removes your both errors.

like image 42
Ronak Badjatya Avatar answered Nov 12 '22 09:11

Ronak Badjatya


Probaly you are getting the error on an Activity. Assuming as so, where you have

public class MainActivity extends ActionBarActivity {

you need to replace by

public class MainActivity extends AppCompatActivity {

you also need to change the import from

import android.support.v7.app.ActionBarActivity;

to

import android.support.v7.app.AppCompatActivity;

and finally, you need to add the dependency to the build.gradle file

implementation 'com.android.support:appcompat-v7:xxx.0.+'

where xxx is the compileSdkVersion version of your App., up to 28.

like image 1
Miguel Silva Avatar answered Nov 12 '22 08:11

Miguel Silva