【问题标题】:Error with R class and Error retrieving parent for item, EclipseR类出错和检索项目的父级时出错,Eclipse
【发布时间】: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 开发。

标签: android eclipse


【解决方案1】:

首先,我将阐明最初的问题 您可能没有正确添加 appcompat 库。有答案here

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

【讨论】:

  • 第二次针对 Eclipse 的警告
【解决方案2】:

对我来说,“junit 测试”软件包有问题 l。几周后,我发现我只需要删除“junit test”包并将它们也从 gradle 文件中删除。然后再次同步项目,一切正常。您可以从“项目结构”设置中的“应用程序”选项卡中删除 junit 测试包。 我希望它也对你有用。

【讨论】:

    猜你喜欢
    • 2014-12-22
    • 2016-08-15
    • 2016-03-04
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多