0
<TextView
    android:id="@+id/first_textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<TextView
    android:id="@+id/second_textview"
    android:layoutbelow="@id/first_textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"  
    android:text="This is my first Android Application!" />

<Button  
    android:id="@+id/first_button"
    android:layoutbelow="@id/second_textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="And this is a clickable button!" /> 

I got error when tried to run. There is a "red" cross at the lines of: - second

Any idea?

2 Answers2

1

At following two places:

  • android:layoutbelow="@id/first_textview"
  • android:layoutbelow="@id/second_textview"

Change layoutbelow to layout_below. Note the use of underscore: _. If you use Ctrl + Spacebar while writing these attributes, eclipse will show you the options available(In case you use eclipse). This way you decrease the chances to such typo mistakes. Hope this helps.

Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
0

Replace your textview and button line-

android:layoutbelow="@id/first_textview"

with this one-

android:layout_below="@+id/first_textview"

Use "@+id" in giving reference, not the "@id" here and you are missing the "_" in the layoutbelow attribute.

amit singh
  • 1,407
  • 2
  • 16
  • 25
  • Actually Amit, he/she need not use `@+id` at that place. `+` is used only when you are declaring the `id` for the first time in the xml. All the other times one can refer to it as `@id` – Shobhit Puri Feb 11 '14 at 21:02
  • @ShobhitPuri ok, then whats the difference between them? – amit singh Feb 12 '14 at 03:06
  • 1
    ^[Difference between “@id/” and “@+id/” in Android](http://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android) :) – Shobhit Puri Feb 12 '14 at 03:09