Android error: Cannot find character class ActionBarActivity

I am currently using Android Studio (beta) 0.8.6 and when I try to run the app on my device the following error appears:

 error: cannot find symbol class ActionBarActivity

      

I was looking for a solution to this error and found the following: Link

Unfortunately I am not under Eclipse.

The code I'm trying 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'm working with API 17. Android 4.1.2 Do you have any suggestions?

Thank!

+13


source to share


5 answers


ActionBarActivity

deprecated below API level 25. Use AppCompatActivity



+27


source


The build.gradle

add the following line to the unit dependencies

:

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

      

Also make sure compileSdkVersion and targetSdkVersion are set to 21 in the block android

.



Then sync your project. If autoimport

disabled - add this import:

import android.support.v7.app.ActionBarActivity;

      

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

+2


source


Have you included the android.support.v7.app library project in your project ?. You need this library to use the action bar.

Please refer to this link. enter link here

0


source


ActionBarActivity

is not a standard Android component. You need to use lib support ( docs ) for this class to be available ( docs )

Base class for actions that use the feature support library action bar.

0


source


You need to add the following imports to your activity:

import android.support.v7.app.ActionBarActivity;

      

you need a support library for this. Take a look at this Link

0


source







All Articles