【问题标题】:Android - java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12Android - java.lang.UnsupportedOperationException:无法转换为维度:type=0x12
【发布时间】:2013-07-20 09:03:48
【问题描述】:

我正在尝试为我的 android 应用程序制作 UI,但它崩溃并且错误是

"java.lang.RuntimeException: 无法启动活动 组件信息{com.example.test/com.example.test.MainActivity}: java.lang.UnsupportedOperationException:无法转换为维度: 类型=0x12"

这是我的 XML 代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">

    <EditText
        android:id="@+id/symbolName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapCharacters"
        android:textColor="#ffffffff" >
    </EditText>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/RadioButton01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/RadioButton02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/RadioButton03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/condition" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="@+id/RadioButton03">

        <EditText 
            android:inputType="number"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Alert"/>

</LinearLayout>

我做错了什么?有什么想法吗?

【问题讨论】:

    标签: android xml layout android-linearlayout


    【解决方案1】:

    您在此行提供了无效资源:

    android:layout_marginTop="@+id/RadioButton03"
    

    尺寸应用于边距,例如

    android:layout_marginTop="@dimen/margin_top"
    

    【讨论】:

      【解决方案2】:

      此行出错

      android:layout_marginTop="@+id/RadioButton03"
      

      总代码如下:

      <EditText
          android:id="@+id/symbolName"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="textCapCharacters"
          android:textColor="#ffffffff" >
      </EditText>
      
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:orientation="vertical" >
      
          <RadioButton
              android:id="@+id/radioButton1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="RadioButton" />
      
          <RadioButton
              android:id="@+id/RadioButton01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="RadioButton" />
      
          <RadioButton
              android:id="@+id/RadioButton02"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="RadioButton" />
      
          <RadioButton
              android:id="@+id/RadioButton03"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="RadioButton" />
      </LinearLayout>
      
      <LinearLayout
          android:id="@+id/condition"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" >
      
          <EditText
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:inputType="number" />
      
          <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
      
          <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
      </LinearLayout>
      
      <Button
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Add Alert" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-19
        • 2016-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多