2013-05-19 54 views
5

匹配在这个文件是我的布局下面的错误在此代码错误:没有资源发现在给定的名字

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> 

这是我的琴弦。 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 question = mQuestionBank [mCurrentIndex] .getQuestion(); mQuestionTextView.setText(question); mQuestionBank是的,我问 getQuestion()的所有问题阵列是我得到的问题

和next_button我不知道我做错了什么,因为我把它上的strings.xml 第二误差getter方法任何人都可以请我帮助我

+1

机器人:ID = “@ ID/question_text_view” 应该是机器人:ID = “@ + ID/question_text_view” 相同为按钮机器人:id =“@ + id/next_button” – Raghunandan

+1

plz see [更多资源类型](h ttp://developer.android.com/guide/topics/resources/more-resources.html#Id)在xml中为Views定义id。您需要使用''而不是''来将id放置在strings.xml文件中,或者您可以为它创建单独的文件,如ids.xml –

回答

7

机器人:ID = “@ ID/question_text_view” 应该是机器人:ID = “@ + ID/question_text_view” 相同为按钮机器人:ID = “@ ID/next_button”应该是机器人: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

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

0

你应该小心使用ID的意见。在你的TextView和你的按钮视图中,你忘记了ID属性中的'+'。据我所知,你尝试用ID来引用另一个视图。如果您使用'+',则为该视图创建一个新ID。

修正版本:

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

链接可能的文件夹路径太长 比如我的“E:\项目\手机\ SixworldGit \ sixworld \项目\ sixworld \ SW_Vietnam \ 2.3。 2.0.20160711_Android_MoboSDKAll_lucgioi_20160711_1805 \ 2.3.2.0.20160711_Android_MoboSDKAll \ MoboSDK \参考\ MoboSDKAll \ RES \可拉伸”

相关问题