【问题标题】:Can not running App on android studio无法在 android studio 上运行 App
【发布时间】:2015-09-22 16:11:34
【问题描述】:

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

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

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

请告诉我如何解决此错误。

代码: 公共类 MainActivity 扩展 Activity {

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

style.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.+'
}

【问题讨论】:

  • 将您的 compilesdkversion 从 23 更改为 21

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


【解决方案1】:

您必须将主题更改为 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>

【讨论】:

  • 感谢您的回答,但我有一个问题,我应该修改 build.gradle 文件吗?
  • 不需要!如果此回复回答了您的问题,请投票。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-19
  • 2018-10-24
  • 2016-05-25
  • 2021-01-30
相关资源
最近更新 更多