Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android error: cannot find symbol class ActionBarActivity

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!

like image 573
Mikep3823 Avatar asked Nov 10 '14 07:11

Mikep3823


3 Answers

ActionBarActivity was deprecated below API level 25. Instead use AppCompatActivity

like image 132
Aaron Dancygier Avatar answered Nov 04 '22 03:11

Aaron Dancygier


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.

like image 43
localhost Avatar answered Nov 04 '22 03:11

localhost


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

like image 1
Tim Botha Avatar answered Nov 04 '22 02:11

Tim Botha