Android ActionBarActivity 无法解析符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21316055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:20:43  来源:igfitidea点击:

ActionBarActivity cannot resolve a symbol

androidandroid-studio

提问by Sumit

In my android Studio, Compiler is not able to locate ActionBarActivity. Because of it, I am getting many errors. The compiler is not able to import the ActionBarActivityand ActionBarclass. These are the lines where compiler is throwing error:

在我的 android Studio 中,Compiler 无法找到ActionBarActivity. 正因为如此,我收到了很多错误。编译器无法导入ActionBarActivityActionBar类。这些是编译器抛出错误的行:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;

I tried to search on stackoverflow before asking a question. The answer i got is for the eclipse which is to add the library. I tried doing it in Android Studio, but didn't get anything.

在提出问题之前,我尝试在 stackoverflow 上进行搜索。我得到的答案是用于添加库的 Eclipse。我尝试在 Android Studio 中执行此操作,但没有得到任何结果。

回答by pyus13

Follow the steps mentioned for using support ActionBar in Android Studio(0.4.2) :

按照提到的在 Android Studio(0.4.2) 中使用支持 ActionBar 的步骤进行操作:

Download the Android Support Repository from Android SDK Manager, SDK Manager icon will be available on Android Studio tool bar (or Tools -> Android -> SDK Manager).

从 Android SDK Manager 下载 Android Support Repository,Android Studio 工具栏(或Tools -> Android -> SDK Manager)上将提供 SDK Manager 图标。

enter image description here

在此处输入图片说明

After download you will find your Support repository here

下载后,您将在此处找到您的支持存储库

$SDK_DIR\extras\android\m2repository\com\android\support\appcompat-v7

Open your main module's build.gradlefile and add following dependency for using action bar in lower API level

打开主模块的build.gradle文件并添加以下依赖项以在较低的 API 级别使用操作栏

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

Sync your project with gradle using the tiny Gradle icon available in toolbar (or Tools -> Android -> Sync Project With Gradle Files).

使用工具栏(或Tools -> Android -> Sync Project With Gradle Files)中提供的微小 Gradle 图标将您的项目与 gradle 同步。

There is some issue going on with Android Studio 0.4.2 so check this as well if you face any issue while importing classes in code.

Android Studio 0.4.2 存在一些问题,因此如果您在代码中导入类时遇到任何问题,请检查此问题。

Import Google Play Services library in Android Studio

在 Android Studio 中导入 Google Play 服务库

If Required follow the steps as well :

如果需要,也请按照以下步骤操作:

  • Exit Android Studio
  • Delete all the .iml files and files inside .idea folder from your project
  • Relaunch Android Studio and wait till the project synced completely with gradle. If it shows an error in Event Log with import option click on Import Project.
  • 退出 Android Studio
  • 从项目中删除 .idea 文件夹中的所有 .iml 文件和文件
  • 重新启动 Android Studio 并等待项目与 gradle 完全同步。如果它在带有导入选项的事件日志中显示错误,请单击导入项目。

This is bug in Android Studio 0.4.2 and fixed for Android Studio 0.4.3 release.

这是 Android Studio 0.4.2 中的错误,已针对 Android Studio 0.4.3 版本修复。

回答by Ronak Badjatya

If the same error occurs in ADT/Eclipse

如果在 ADT/Eclipse 中出现同样的错误

Add Action Bar Sherlock libraryin your project.

在您的项目中添加Action Bar Sherlock 库

Now, to remove the "import The import android.support.v7 cannot be resolved"error download a jar file named as android-support-v7-appcompat.jarand add it in your project libfolder.

现在,要删除“无法解决导入 android.support.v7”错误,请下载名为android-support-v7-appcompat.jar的 jar 文件并将其添加到您的项目lib文件夹中。

This will surely removes your both errors.

这肯定会消除您的两个错误。

回答by Akshay

Make sure that in the path to the project there is no foldername having whitespace. While creating a project the specified path folders must not contain any space in their naming.

确保在项目路径中没有包含空格的文件夹名。创建项目时,指定的路径文件夹不得在其命名中包含任何空格。