gpt4 book ai didi

android - 错误 : No resource found that matches the given name

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:45 25 4
gpt4 key购买 nike

在此文件中是我的布局,此代码中显示以下错误

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

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

我知道字符串上有 know question_text_view 但我确实在我的 Activity 中制作了一个数组来处理所有问题 mQuestionTextView =(TextView)findViewById(R.id.question_text_view); int question = mQuestionBank[mCurrentIndex].getQuestion(); mQuestionTextView.setText(问题);mQuestionBank 是我提出的所有问题的数组getQuestion() 是我获取问题的 getter 方法

next_button 的第二个错误我不知道我做错了什么,因为我将它包含在 strings.xml 中谁能帮帮我

最佳答案

android:id="@id/question_text_view"应该是 android:id="@+id/question_text_view"对于按钮 android:id="@id/next_button"应该是 android:id="@+id/下一个按钮”

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

身份证

任何 View 对象都可能有一个与之关联的整数 ID,以在树中唯一标识 View 。编译应用程序时,此 ID 被引用为整数,但 ID 通常在布局 XML 文件中作为字符串分配在 id 属性中。这是所有 View 对象(由 View 类定义)共有的 XML 属性,您将经常使用它。 XML 标记内 ID 的语法是:

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

在你的情况下,你认为按钮的 id 是 android:id="@id/next_button"。您正在引用 Android 资源 ID(假设)。这不存在。 textview 也是一样的。因此,您会收到找不到资源的错误。

有关更多信息,请查看下面的链接

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

关于android - 错误 : No resource found that matches the given name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16638905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com