我是eclipse的android开发新手,在创建新项目时我遇到两个错误。一个是在src文件夹中,主要活动是:
“R无法解析为变量”
还有res文件夹,values,styles.xml:
“C:\ Users \ userName \ workspace \ test \ res \ values \ styles.xml:7:error:检索项目的父项时出错:找不到与给定名称”Theme.AppCompat.Light“匹配的资源。”
我得到了相同的错误3次,一次是在值-v11中使用appcompat.light,另一次是使用黑暗操作栏。我真的不知道该怎么办。我觉得我好笨。甚至都没能在我的手机上测试任何东西。
如果你可以帮助我,我会非常感激。
以下是一些代码:
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
并在styles.xml中
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:2)
首先,我将对原始问题进行一些阐述 您可能没有正确添加appcompat库。有一个答案here
第二件事是; Eclipse不再是Android开发支持的IDE。您应该从Android开发人员网站http://developer.android.com下载Android Studio 在Android工作室中添加此库并继续工作会更容易。
答案 1 :(得分:0)
对我来说这是&#34; junit test&#34;包裹几周之后,我发现我只需删除&#34; junit test&#34;打包并从gradle文件中删除它们。然后再次同步项目,每件事都运作良好。您可以从&#34; app&#34;删除junit测试包。选项卡&#34;项目结构&#34;设置。 我希望它也适合你。