当我在 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/