R类错误,并且检索项目的父项时出错,Eclipse [英] Error with R class and Error retrieving parent for item, Eclipse

查看:31
本文介绍了R类错误,并且检索项目的父项时出错,Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是eclipse的Android开发新手,在创建新项目时遇到两个错误.一个在src文件夹中,主要活动说:

"R无法解析为变量"

以及在res文件夹中,还包含values.styles.xml:

"C:\ Users \ userName \ workspace \ test \ res \ values \ styles.xml:7:错误:检索项目的父项时出错:找不到与给定名称'Theme.AppCompat.Light'相匹配的资源."

我收到3次相同的错误,一次是在值v11中使用appcompat.light,另一次是深色动作栏.我真的不知道该怎么办.我觉得我好笨.甚至无法测试我手机中的任何内容.

如果您能帮助我,我将非常感激.

这是一些代码:

  package com.example.test;导入android.app.Activity;导入android.os.Bundle;公共类MainActivity扩展了Activity {@Override受保护的void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}} 

以及styles.xml

 < resources><!-基本应用程序主题,取决于API级别.该主题被替换由AppBaseTheme提供,位于更新设备上的res/values-vXX/styles.xml中.->< style name ="AppBaseTheme" parent ="Theme.AppCompat.Light"><!-可以在较新的API级别中使用主题自定义res/values-vXX/styles.xml,而自定义与向后兼容可以在这里进行.-></style>< ;!-应用程序主题.->< style name ="AppTheme" parent ="AppBaseTheme"><!-并非特定于特定API级别的所有自定义项都可以在此处进行.-></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-sdkandroid:minSdkVersion ="8"android:targetSdkVersion ="21"/><应用android:allowBackup ="true"android:icon ="@ drawable/ic_launcher"android:label ="@ string/app_name"android:theme ="@ style/AppTheme"><活动android:name =.MainActivity"android:label ="@ string/app_name"><意图过滤器>< action android:name ="android.intent.action.MAIN"/>< category android:name ="android.intent.category.LAUNCHER"/></intent-filter></activity></应用程序></manifest> 

解决方案

首先,我将阐明原始问题您可能没有正确添加appcompat库.在此处

第二件事是;Eclipse不再是Android开发支持的IDE.您应该从Android开发人员网站上下载Android Studio,该网站为 http://developer.android.com 在Android Studio中添加该库并继续工作要容易得多.

I'm new at android development with eclipse, and when creating a new project i get two errors. One is in the src folder, main activity saying:

"R cannot be resolved to a variable"

And also in res folder, values, styles.xml:

" C:\Users\userName\workspace\test\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'."

I get the same error 3 times, one in values-v11 with appcompat.light andthe other with dark action bar. I really don't know what to do. i Feel stupid. Haven't even been able to test anything in my phone.

If you could help me with this, i'll be really thankful.

Here is some code:

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);
}
 }

and in the 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>

Also the manifest:

<?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>

解决方案

First of all, I'll shed some light on the original issue You might not have added the appcompat library properly. There's an answer here

Second thing is; Eclipse is no longer a supported IDE for Android development. You should download Android Studio from the Android developer website at http://developer.android.com Its a lot easier to add this library in Android studio and continue work.

这篇关于R类错误,并且检索项目的父项时出错,Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆