android - 无法在 android studio 上运行 App

标签 android android-studio gradle android-manifest android-theme

当我在 android studio 中创建一个新项目时,我发现 Activity 类最初扩展了 AppCompatActivity,我必须将其更改为扩展
改为 Activity 。

但我面临的问题是,R 类无法识别,我收到错误“无法解析符号 R”。我发布了 build.gradle
下面的文件,在我看来它没有错误。

此外,在尝试找出解决方案后,我检查了所有 xml 文件,发现 style.xml “posted below”在“Theme.AppCompat.Light.DarkActionBar”处有错误
和 android studio 无法解决它。

请让我知道如何解决此错误。

代码 :
公共(public)类 MainActivity 扩展 Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.xxx.xxx);//cant resolve symbol R
    }
}

样式.xml :

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">//cant resolve symbol Theme+cant resolve symbol AppCompat
        <!-- Customize your theme here. -->
    </style>

</resources>

gradle.build :
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.com.bt_11"
        minSdkVersion 19
        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:23.+'
}

最佳答案

您必须将主题更改为 Holo Light 或 Holo Dark 或 Material 主题,如下所示;

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

关于android - 无法在 android studio 上运行 App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32721761/

相关文章:

javascript - 如何在模拟器上运行 ionic 应用程序?

android - Mac、Android Studio、Emulator、SQLite 数据库——实际找到目录?

java - 错误 :(23, 26) 不允许字符串类型(位于 'src' ,值为 'pen' )。

从 Android Studio 0.54 更新到 0.81 "NoSuchMethodError"后,Gradle 不会同步

gradle - 如何在Gradle Copy任务中仅对一个 “from”执行重命名?

android - 为原生相机应用程序设置视频格式

android - 如何检测Android屏幕亮度是否发生变化?

java - 通过java代码记录用户选择并更改textview字符串

spring-boot - Spring Boot 1和Gradle:ClassNotFoundException SpringApplicationBuilder

android - APK打包过程中文件重复或Android UnsatisfiedLinkError