Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No resource found that matches the given name

Tags:

android

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').

this is the layout file

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

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>

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

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

like image 913
john parker Avatar asked May 19 '13 20:05

john parker


1 Answers

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

    <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

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:

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).

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

http://developer.android.com/guide/topics/ui/declaring-layout.html

like image 76
Raghunandan Avatar answered Nov 04 '22 21:11

Raghunandan