错误:未发现的资源匹配给定名称 [英] Error: No resource found that matches the given name

查看:189
本文介绍了错误:未发现的资源匹配给定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个文件是我的布局以下错误在这code显示

In this file are my layouts the following errors display in this code

error: Error: No resource found that matches the given name (at 'id' with value '@id/question_text_view').
error: Error: No resource found that matches the given name (at 'id' with value '@id/next_button').

这是布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        />
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >
        <Button 
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/true_button"
        />
        <Button 
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"
        />
    </LinearLayout>
        <Button 
        android:id="@id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"
        />
</LinearLayout>

这是我的strings.xml

This is my strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>

        <string name="app_name">GeoQuiz</string>
        <string name="true_button">True</string>
        <string name="false_button">False</string>
        <string name="correct_toast">Correct</string>
        <string name="next_button">Next</string>
        <string name="incorrect_toast">Incorrect</string>
    <string name="action_settings">Settings</string>
    <string name="question_founder">Frank Reed Horton Founded APO on december 25 1947</string>
    <string name="question_chief">Willy Wonka was known as a cheif</string>
    <string name="question_lady">The first lady that became president in APO was Mary Katz</string>
    <string name="question_president">Our current President of the Delta Rho chapter is  john dolan</string>
<string name="question_alphabets">Alpha, Beta, Gamma, Delta, Epsilon, Eta, Zeta</string>
</resources>

我知道,有知道question_text_view在弦上,但我没有让我的活动一个数组通吃的问题         mQuestionTextView =(TextView中)findViewById(R.id.question_text_view);         INT问题= mQuestionBank [mCurrentIndex] .getQuestion();         mQuestionTextView.setText(问题); mQuestionBank是我提出的所有问题,阵列 getQuestion()是我的getter方法​​获取的问题

I know that there is know question_text_view on the strings but I did make a array in my activity that takes all of the questions mQuestionTextView =(TextView)findViewById(R.id.question_text_view); int question = mQuestionBank[mCurrentIndex].getQuestion(); mQuestionTextView.setText(question); mQuestionBank is a array of all questions that I ask getQuestion() is my getter method for getting the question

和next_button我不知道我做错了什么,因为我把它在strings.xml中的第二个错误 任何人都可以请帮我

and the second error for next_button i dont know what I did wrong since I included it on the strings.xml can anyone please help me out

推荐答案

机器人:ID =@ ID / question_text_view应该是机器人:ID =@ + ID / question_text_view一样的按钮机器人:ID =@ ID / next_button应该是机器人:ID =@ + ID / next_button

android:id="@id/question_text_view" should be android:id="@+id/question_text_view" same for button android:id="@id/next_button" should be android:id="@+id/next_button"

的TextView

    <TextView
    android:id="@+id/question_text_view" //  missing + in your xml code
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="24dp"
    />

按钮

    <Button 
    android:id="@+id/next_button"  // missing + in your xml code
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next_button"
    /> 

ID

任何视图对象可以有与之相关联的整数ID,唯一标识在树中的视图。当应用程序被编译,这个ID被参考为一个整数,但ID通常分配布局XML文件作为字符串中,在id属性。这是一个XML属性适用于所有视图对象(由视图类中定义),你会经常使用它。语法一个ID,一个XML标签内是:

Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute. This is an XML attribute common to all View objects (defined by the View class) and you will use it very often. The syntax for an ID, inside an XML tag is:

将在符号(@)在字符串的开头表示XM​​L解析器应该解析和扩展ID字符串的其余部分,将其识别为一个ID资源。的加号(+)指这是必须创建并添加到我们的资源(在R.java文件)的新的资源名即可。

在你的情况按钮,您认为id是机器人:ID =@ ID / next_button。你引用的Andr​​oid资源ID(假设)。本不存在。这是相同的TextView。因此,你得到的资源没有发现错误。

In your case your consider id of button is as android:id="@id/next_button". You are referencing Android resource ID (assumes). This does not exist. It's the same for textview. Hence you get Resource not found error.

有关详细信息,请查看下

For more information check the link below

<一个href="http://developer.android.com/guide/topics/ui/declaring-layout.html">http://developer.android.com/guide/topics/ui/declaring-layout.html

这篇关于错误:未发现的资源匹配给定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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