Android的XML错误:[否资源的发现,匹配给定的名称和QUOT;与RelativeLayout的(@ ID / LinearLayout_acc,@ ID / ProgressBar_statu

2023-09-06 01:30:15 作者:生命旳过客

好了,所以这是开始真正激怒我。这个错误弹出在一个非常特殊的,不是很符合逻辑的方式。

Okay, so this is starting to really annoy me. This error pops up in a very special, not very logical way.

让我先出来说,我已经看了看其他的问题,关于这个错误,Google'd它。据我所知道的,发生最类似的问题,因为人们指字符串资源还是其他什么东西不是在同一个布局文件,他们放错了'+'在'@ ID +'或类似的东西。

Let me start out by saying that I have already looked at the other questions regarding this error, Google'd it too. As far as I can tell, most similar problems occur because people refer to a String resource or something else not within the same layout file, they misplace the '+' in '@id+' or something similar.

我遇到的问题出现在了 RelativeLayout的布局.xml文件。这包含了一个 TableLayout ,两个的LinearLayout 含S的一些文字,最后一个进度。我要的是进度条,使用 Android的相对布局相一致:layout_alignParentBottom =真正的键,然后对准两线布局上面的进度条(底部线布局对准上面的进度条,上面的底部线性布局其他对齐)。

The problem I am having occurs in a layout .xml file with a RelativeLayout. This contains a TableLayout, two LinearLayouts containing some text and finally a ProgressBar. What I want is the progress bar to be aligned with the relative layout using android:layout_alignParentBottom="true" and then align the two linear layouts above the progress bar (the bottom linear layout aligning above the progress bar, the other aligning above the bottom linear layout).

有应该足够简单并且看起来好像它的工作原理,即图形视图显示了期望的结果。然而,和这里来的问题,Eclipse的给我一个错误的两个线性布局,

It should be simple enough and looks as if it works, i.e. the graphic view shows the desired result. However, and here comes the problem, Eclipse gives me an error on the two linear layouts,

错误:未发现的资源匹配给定名称(在'layout_above,值为@ ID / LinearLayout_acc')

"Error: No resource found that matches the given name (at 'layout_above' with value '@id/LinearLayout_acc')."

和相同的错误为其他线性布局指的是进度条。我有超过三重检查有没有错别字(该ID的也存在于packagename.R.java),而我试图清理项目十几次。

and the same error for the other linear layout referring to the progress bar. I have more than triple checked that there are no typos (the id's also exist in packagename.R.java), and I have tried cleaning the project a dozen times.

我当储蓄(和汽车大厦)不出现错误,直到我决定要运行该项目。另一个奇怪的事情是,当我指的是底部线性布局的进度条,而不是顶部的线性布局,我没有得到任何错误!

I don't get the error when saving (and auto building), not until I decide to run the project. Another weird thing is that when I refer to the bottom linear layout from the progress bar instead of the top linear layout, I get no error!

我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_activity" >
        <TableLayout
             ... />

        <LinearLayout
            android:id="@+id/LinearLayout_dist"
            android:layout_above="@id/LinearLayout_acc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp" >

            <TextView
                ... />

            <TextView
                ... />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/LinearLayout_acc"
            android:layout_above="@id/ProgressBar_statusScreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

            <TextView
                ... />

            <TextView
                ... />
        </LinearLayout>

        <ProgressBar
            android:id="@+id/ProgressBar_statusScreen"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="16dp" />

</RelativeLayout>

请帮忙,我不知道是什么原因导致这个错误!

Please help, I have no idea what causes this error!

Shrikant附带改变出现的顺序在布局文件中,以便元素参考已经定义当基准是只读其它元素的溶液中。 此外,正如其他人发布的,不断变化的 @id / @ + ID / ,即使是在一个参考,并删除该错误消息。正如马可瓦。写这线程,事情是你有使用 @ + ID / 第一次每个ID被提及,然后使用 @id / 之后,即使第一次可能不是一个定义。

Shrikant came with the solution of changing the order of appearance in the layout file so that elements reference only other elements already defined when the reference is read. Also, as others have posted, changing @id/ to @+id/, even in a reference, does remove the error messages. As Marco W. wrote in this thread, the thing is you have to use @+id/ the first time each id is mentioned and then use @id/ afterwards, even though the first time may not be a definition.

我做了大部分的设计,并设置简称ID在Eclipse的图形化编辑器,因此code,它导致错误消息自动插入。也许这是Eclipse的一个错误。

I made most of the design and set the referred id's in Eclipse's graphical editor, so code that resulted in an error message was automatically inserted. Maybe this is a bug in Eclipse.

推荐答案

请检查下面的code

Please check the below code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher" >

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/LinearLayout_dist"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/LinearLayout_acc"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FIRST" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SECOND" />
   </LinearLayout>

   <LinearLayout
    android:id="@+id/LinearLayout_acc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/ProgressBar_statusScreen"
    android:layout_centerHorizontal="true" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="THIRD" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FOURTH" />
   </LinearLayout>

   <ProgressBar
    android:id="@+id/ProgressBar_statusScreen"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_margin="16dp" />

 </RelativeLayout>

另外,请检查下面的链接。 它说,安卓layout_below =@ ID / myTextView将无法识别的元素ID为myTextView如果你正在使用它的元素之后写入

Also check the following link. It says that android:layout_below="@id/myTextView" won't recognise an element with id "myTextView" if it is written after the element you're using it in.