Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(can't find id reference) No resource matches the given name at

I have the following inside a relative layout.

<TextEdit
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/buttonA"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@id/buttonA" />

<Button
    android:id="@+id/buttonA"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:text="@string/message" >
</Button>

Eclipse gives me these errors at lines android:layout_alignBottom="@id/buttonA" and android:layout_toLeftOf="@id/buttonA" respectively:

error: Error: No resource found that matches the given name (at 'layout_alignBottom' with value '@id/buttonA').

error: Error: No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/buttonA').

Replacing @id/buttonA with @+id/buttonA removes this eclipse error message. Is that the right thing to do? If so, why would that work instead? Doesn't @+id create a new id? I don't want a new id. I want to use the one referenced in the button object. What is the best way to deal with this?

Thanks guys. -Joe

like image 888
J50 Avatar asked May 23 '12 18:05

J50


People also ask

What's the difference between @ID and @+ id?

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

What is the use of resource ID in android?

Resource ID. A unique resource name for the element, which you can use to obtain a reference to the ViewGroup from your application. See more about the value for android:id below. android:layout_height.

What is id value resource Android studio?

Id of a resource is uniq identifier , such as name of a variable. It should be uniq or you will have problems with names.


2 Answers

The layout which you are trying to use as a reference should be defined before it is used as reference i.e. use as 'layout_toLeftOf'.

It is like you have to declare a variable in java before using it. Declare then use it ...

If you need to mention the id before its defined in the file, then you need to use @+id/textView1 instead of @id/textView1

like image 83
erluxman Avatar answered Oct 23 '22 04:10

erluxman


Using @+id is the right way to do it. @+id creates a new id but only if one with that name doesn't already exist.

If you don't want to do that, for this particular simple case it would suffice to move the TextEdit below the Button.

like image 43
K-ballo Avatar answered Oct 23 '22 03:10

K-ballo