Android的错误:无法找到符号类ActionBarActivity

Android的错误:无法找到符号类ActionBarActivity

问题描述:

我目前使用Android的工作室(测试版)0.8.6,当我尝试运行一个应用程序到我的设备,将出现以下错误:

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

我抬头对这个错误的解决方案,并发现了以下几点:
Link

可惜我不是的Eclipse下。

Unfortunately I am not under Eclipse.

在code我尝试运行如下:

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);
    }

}

我与API 17.运行Android 4.1.2
你有什么建议家伙?

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

谢谢!

在你的的build.gradle 添加以下在依赖行块:

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

另外,还要确保有 compileSdkVersion targetSdkVersion 下的设置为 21 机器人块。

然后同步您的项目。如果 AUTOIMPORT 已禁用 - 添加此输入:

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

import android.support.v7.app.ActionBarActivity;

另外需要更新的Andr​​oid Studio和gradle这个插件的最新版本。

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