【发布时间】: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