0

I cannot figure out why I am getting this error. From a quick google search, all I could figure out was that there is some syntax error, but I still couldn't quite figure it out.

enter image description here

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent">

       <Button
           android:id="@+id/but1"
           android:layout_width="100dp"
           android:layout_height="200dp"
           android:text="button1"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/but2"
        android:text="button2"/>
    </LinearLayout>


    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
Omkar
  • 3,040
  • 1
  • 22
  • 42

2 Answers2

0

try to add xmlns:app="http://schemas.android.com/apk/res-auto" in like below code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" //change here
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent">

   <Button
       android:id="@+id/but1"
       android:layout_width="100dp"
       android:layout_height="200dp"
       android:text="button1"/>
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/but2"
    android:text="button2"/>
</LinearLayout>


<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Omkar
  • 3,040
  • 1
  • 22
  • 42
0

Namespace prefixes (app in app:layout_constraintBottom_toBottomOf) must be declared (bound to a namespace URI). Your error indicates that it is not.

To declare a namespace, and a namespace declaration of the form

xmlns:xyz="http://example.com/something"

to the common ancestor beneath which you wish the declaration to apply.

The template from which you copied your XML should have such a declaration already. If you can no longer find it, you can check the documentation or google for examples. In this case, it appears that app:layout_constraintBottom_toBottomOf should be declared as follows:

xmlns:app="http://schemas.android.com/apk/res-auto"

You should repeat this process for any other used but undefined namespace prefixes:

xmlns:android="http://schemas.android.com/apk/res/android"

etc.

kjhughes
  • 106,133
  • 27
  • 181
  • 240