25

I am currently Using Android Studio (Beta) 0.8.6 and when I try to run an app into my device, the following error appears:

 error: cannot find symbol class ActionBarActivity

I looked up for the solution for this error and found the following: Link

Unfortunately I am not under Eclipse.

The code I try to run is the following:

package com.example.doblevxv5.sunny;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/**
 * Created by Doble Vx V5 on 8/11/14.
 */
public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new ForecastFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

I am running with API 17. Android 4.1.2 Do you have any suggestion guys?

Thanks!

Community
  • 1
  • 1
Mikep3823
  • 261
  • 1
  • 3
  • 3
  • This is because the class couldn't find ActionBarActivity class. The mistake you have done is you didn't import ActionBarActivity. Here you go `import android.support.v7.app.ActionBarActivity;` For this you need to import appCompat_v7 to your workspace! If you are a beginner i would encourage you to start working on with Eclipse. – Kavin Prabhu Nov 10 '14 at 08:00
  • I wish I could use another IDE. Unfortunately I have to use Android Studio for this course I am taking. I already imported but here is what the log says: Error:(6, 30) error: package android.support.v7.app does not exist – Mikep3823 Nov 10 '14 at 08:15
  • Go to your build.gradle and add ` compile 'com.android.support:appcompat-v7:21.0.+'` and build your gradle and give that import statement. – Kavin Prabhu Nov 10 '14 at 08:18
  • When I try to import that into the build.gradle the following mesagge appears: Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'. – Mikep3823 Nov 10 '14 at 08:25
  • I think you missing out lot of basic things. I encourage you to learn and know about Android Studio IDE first. You need to set your project to 5.0 and i hope u downloaded latest api's. Open SDK manager and install or update latest api specially tools category. – Kavin Prabhu Nov 10 '14 at 08:43

6 Answers6

57

ActionBarActivity was deprecated below API level 25. Instead use AppCompatActivity

Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26
Aaron Dancygier
  • 1,996
  • 19
  • 20
  • Thanks Aaron, this solved it for me! Had to switch out a few locations where the old import was used. – patrics Jul 10 '18 at 15:28
2

In your build.gradle add following line under dependencies block:

compile 'com.android.support:appcompat-v7:21.0.+'

Also make sure to have compileSdkVersion and targetSdkVersion set to 21 under android block.

Then Sync your project. If autoimport is disabled - add this import:

import android.support.v7.app.ActionBarActivity;

Also update Android Studio and gradle plugin to the latest version.

localhost
  • 5,568
  • 1
  • 33
  • 53
1

You need to add the following import to your activity:

import android.support.v7.app.ActionBarActivity;

for this to work you require the support library. Take a look at this Link

Community
  • 1
  • 1
Tim Botha
  • 51
  • 3
  • Just added it and it shows the following: Error:(6, 30) error: package android.support.v7.app does not exist I did take a look before to that link and still does not work. Thanks! – Mikep3823 Nov 10 '14 at 08:10
  • Have you downloaded the support package? here is another link that might help https://developer.android.com/tools/support-library/setup.html – Tim Botha Nov 10 '14 at 08:26
0

have you included the android.support.v7.app library in your project?. You need this library in order to use the Action bar.

Please refer to this link. enter link description here

chkm8
  • 1,302
  • 1
  • 13
  • 34
0

ActionBarActivity is not standard component of Android. You need to use support lib (docs) to have this class available (docs)

Base class for activities that use the support library action bar features.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

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.

Miguel Tomás
  • 1,714
  • 1
  • 13
  • 23