2

I'm getting the above error with my xml below. What is my issue?

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

  <TextView
    android:id="@+id/question"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:text="what is your name?"
    android:textColor="@android:color/black" />

  <RadioGroup
    android:id="@+id/answer_group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/question"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp" >

    <RelativeLayout
      android:id="@+id/radio_group_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <RadioButton
        android:id="@+id/option1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="paru"
        android:textColor="@android:color/black" />

      <RadioButton
        android:id="@+id/option2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@id/option1"
        android:text="mani"
        android:textColor="@android:color/black" />

      <RadioButton
        android:id="@+id/option3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/option1"
        android:text="sankar"
        android:textColor="@android:color/black" />

      <RadioButton
        android:id="@+id/option4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/option2"
        android:layout_marginLeft="@id/option2"
        android:layout_toRightOf="@id/option3"
        android:text="venkat"
        android:textColor="@android:color/black" />

    </RelativeLayout>
  </RadioGroup>
</RelativeLayout>

and my logcat shows:

java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
    at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5768)
indivisible
  • 4,892
  • 4
  • 31
  • 50
John
  • 1,407
  • 7
  • 26
  • 51

1 Answers1

4

Remove android:layout_marginLeft="@+id/option2" from your option4 RadioButton.As you cannot give any view as margin.And also make your alignment view ids as @+id and not @id

Try below data :

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

    <TextView
        android:id="@+id/question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="what is your name?"
        android:textColor="@android:color/black" />

    <RadioGroup
        android:id="@+id/answer_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/question"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp" >

        <RelativeLayout
            android:id="@+id/radio_group_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <RadioButton
                android:id="@+id/option1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="paru"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/option2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@+id/option1"
                android:text="mani"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/option3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/option1"
                android:text="sankar"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/option4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/option2"
                android:layout_toRightOf="@+id/option3"
                android:text="venkat"
                android:textColor="@android:color/black" />
        </RelativeLayout>
    </RadioGroup>

</RelativeLayout>
Manishika
  • 5,478
  • 2
  • 22
  • 28
  • its worked me fine thank u so much, after this i got a runtime exception like : java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView form if (convertView == null) { view = mInflater.inflate(R.layout.questions_lits_item,parent, true); } else { view = convertView; } – John May 29 '14 at 21:27
  • You saved me a lot of time. Thanx. – Ravi Ranjan Singh Feb 09 '16 at 11:54