【问题标题】:java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12 in android [duplicate]java.lang.UnsupportedOperationException:无法转换为维度:android中的type = 0x12 [重复]
【发布时间】:2014-07-19 10:15:56
【问题描述】:

我在下面的 xml 中遇到上述错误。我的问题是什么?

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

我的 logcat 显示:

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)

【问题讨论】:

    标签: android xml layout


    【解决方案1】:

    从您的option4RadioButton 中删除android:layout_marginLeft="@+id/option2"。因为您不能将任何视图作为边距。并且还将您的对齐视图ID 设为@+id 而不是@id

    试试下面的数据:

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

    【讨论】:

    • 它工作得很好,非常感谢你,在此之后我得到了一个运行时异常,例如: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); } 其他 { 视图 = 转换视图; }
    • 你为我节省了很多时间。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    相关资源
    最近更新 更多