Android Studio 1.0.2 新项目 - 无法解析符号“ActionBarActivity" [英] Android Studio 1.0.2 new project - Cannot resolve symbol 'ActionBarActivity'

查看:29
本文介绍了Android Studio 1.0.2 新项目 - 无法解析符号“ActionBarActivity"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑.今天我刚刚重新安装了 Android Studio Version 1.0.2(和 Android SDK),因为我昨天在创建一个新项目时遇到了一些问题.本来希望只要重装就可以解决,但实际上问题依然存在,不知道怎么解决.

I’m very confused. Today I just reinstalled Android Studio Version 1.0.2 (and the Android SDK) because I had some problems yesterday when I created a new project. I hoped that I could solve them by just reinstall everything, but actually the problem still exists and I don’t know how to solve it.

在 Android Studio 中创建一个新项目并切换到我的 MainActivity(我没有更改其中一个文件中的任何内容)后,我总是在文件中显示以下错误.

After I created a new project in Android Studio and switch to my MainActivity (I didn't changed anything in one of the files), I always get the following errors displayed in the file.

MainActivity.class:

package com.android.testapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


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

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

错误:

  • 无法解析符号ActionBarActivity"
  • 无法解析方法onCreate(android.os.Bundle)"
  • 无法解析方法setContentView(int)"
  • 无法解析方法getMenuInflater()"
  • 无法解析方法setContentView(int)"
  • 无法解析方法onOptionsItemSelected(android.view.MenuItem)"

项目:build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

模块:build.gradle

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.android.testapplication"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

我已经重建并清理了我的项目和 'Sync Project with Gradle Files' 但它们都没有解决我的问题.

I already rebuild and cleaned my project and 'Sync Project with Gradle Files' but none of them fixed my issues.

有趣的是,我可以在我的智能手机上编译和运行我的项目......

The funny thing is, that I can compile and run my project on my smartphone…

PS:我想这似乎是一个 gradle 问题,因为每当我添加一个新库,例如 'com.google.android.gms:play-services:6.5.87' 然后尝试导入它'import com.google.android.gms.gcm.GoogleCloudMessaging;'.我还显示了 'Cannot resolve symbol...' 错误.我没有遵守 GCM 服务......

PS: I guess it seems to be a gradle issue, because whenever I add a new library such as 'com.google.android.gms:play-services:6.5.87' and then try to import it 'import com.google.android.gms.gcm.GoogleCloudMessaging;'. I also get the 'Cannot resolve symbol…' error displayed. I didn’t complied it with the GCM Service…

提前感谢您的帮助:)

推荐答案

对于需要它的每个人,您可以在这里找到它:

For everyone who needs it, you can find it here:

Android Studio 提示无法解析符号";但项目编译

如果链接断开:

File > Invalidate Caches/Restart...Invalidate and Restart 解决问题.

File > Invalidate Caches / Restart... and Invalidate and Restart to solve the issue.

这篇关于Android Studio 1.0.2 新项目 - 无法解析符号“ActionBarActivity"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆