在styles.xml修复错误产生R.java:没有资源发现的名字“Theme.AppCompat.Light” [英] Fixing Error in styles.xml to generate R.java : No resource found name 'Theme.AppCompat.Light'

查看:334
本文介绍了在styles.xml修复错误产生R.java:没有资源发现的名字“Theme.AppCompat.Light”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid,我试图运行我的第一个程序。但是,根据我在互联网上搜索,我想我不能导入 mypackage.R ,因为 r.java 尚未生成,因为在我style.xml文件错误。我寻觅周围试图找出如何解决这些,但我不能找到一种可行的修复。在 styles.xml 的误差

 错误:错误检索父项:没有资源的发现,匹配给定的名字Theme.AppCompat.Light
 

有谁知道如何解决这个问题?

![在style.txt错误] [1]

下面是code我使用的:

 包com.example.test;

进口android.os.Bundle;
进口android.app.Activity;
进口android.view.Menu;
进口android.view.MenuItem;

公共类MainActivity延伸活动{

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    。getMenuInflater()膨胀(R.menu.activity_main,菜单);
    返回true;
}
}
 

更新: 这里是styles.xml:

 <资源>

<! - 
    基本应用的主题,依赖于API级别。这个主题被替换
    通过AppBaseTheme从RES /值-VXX /上较新的设备styles.xml。
 - >
<样式名称=AppBaseTheme父=Theme.AppCompat.Light>
    <! - 
        在新的API级别可以在可用主题自定义
        RES /值-VXX / styles.xml,而自定义相关
        向后兼容性可以去这里。
     - >
< /风格>

<! - 应用主题。 - >
<样式名称=AppTheme父=AppBaseTheme>
    <! - 所有的定制,这不是针对特定的API级别的可以去这里。 - >
< /风格>

< /资源>
 

更新2: 这里是AndroidManifest.xml中

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.test
安卓版code =1
机器人:VERSIONNAME =1.0>

<用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =19/>

<应用
    机器人:allowBackup =真
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名称=com.example.test.MainActivity
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>

< /舱单>
 

解决方案

您要使用 Theme.AppCompat.Light 主题,这是一个库项目。你必须引用该库项目到项目中。

现在,首先应检查是否已经安装了这个库项目如下...

开始窗口 - > Android的SDK管理器,然后一个窗口名为 Android的SDK管理器,会出现以下

如果未安装 Android的支持库再进行安装。你可以看到 Android的支持库从下面的Andr​​oid开发者网站设置的更多信息。

支持库设置

Android的支持库设置完成后,引用该库到您的项目,从这个路径...

  Android的SDK /演员/安卓/支持/ V7 / appcompat
 

要引用,请按照下列步骤操作:

  1. 文件 - > 导入(Android的SDK \演员\机器人\ SUPPORT \第7版)。选择 appcompat
  2. 项目 - > 属性 - > 机器人。在部分库的添加,然后选择 appCompat

现在,清理并生成项目并运行它。我想,毕竟这些,您的问题将得到解决。

I am new to Android and am trying to run my first program. However, based on my searches across the internet, I think that I can't import mypackage.R because r.java has not been generated because of errors in my style.xml files. I have searched around trying to figure out how to fix these but I can't find a fix that works. The error in styles.xml is

error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'

Does anyone know how to fix this?

![Errors in style.txt][1]

Here is the code I am using:

package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

UPDATE: Here is 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>

UPDATE 2: Here is AndroidManifest.xml

<?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="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test.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>

解决方案

You are trying to use Theme.AppCompat.Light theme which is a library project. You have to reference this library project to your project.

Now, at first, check that you have installed this library project as follows...

Go Window-->Android SDK Manager then a window named Android SDK Manager will appear as below.

If the Android Support Library is not installed then install it. You can see more information about Android Support Library setup from the below Android Developer site.

Support Library Setup

After Android Support Library setup completion, reference the library to your project from this path...

android-sdk/extras/android/support/v7/appcompat

To reference, follow these steps:

  1. File->Import (android-sdk\extras\android\support\v7). Choose "appcompat"
  2. Project-> properties->Android. In the section library "Add" and choose "appCompat"

Now, clean and build your project and run it. I think after all of these, your problem will be solved.

这篇关于在styles.xml修复错误产生R.java:没有资源发现的名字“Theme.AppCompat.Light”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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