【发布时间】:2017-05-15 13:39:36
【问题描述】:
我是使用 eclipse 进行 android 开发的新手,在创建新项目时出现两个错误。一个在 src 文件夹中,主要活动说:
“R 无法解析为变量”
还有 res 文件夹,values,styles.xml:
“C:\Users\userName\workspace\test\res\values\styles.xml:7:错误:检索项目的父项时出错:找不到与给定名称“Theme.AppCompat.Light”匹配的资源。”
我收到同样的错误 3 次,一次在 values-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>
【问题讨论】:
-
请使用 Android Studio 而不是 Eclipse。 Google 不再支持使用 Eclipse 进行 Android 开发。