Android xml error: "No resource found that matches the given name" with RelativeLayout (@id/LinearLayout_acc, @id/ProgressBar_statusScreen)

stemadsen picture stemadsen · Jul 26, 2012 · Viewed 71k times · Source

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

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.

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

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,

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

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!

My layout file:

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

Edit with answers

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.

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.

Answer

jeet picture jeet · Jul 26, 2012

change

@id/LinearLayout_acc

to

@+id/LinearLayout_acc