java.lang.UnsupportedOperationException:无法转换为dimension:type = 0x12

时间:2014-02-17 06:49:05

标签: android xml layout

所以我的问题很奇怪。我一直收到这个错误:

java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12

奇怪的是它只发生在4.1.2上。我测试了4.0.3,4.2.2,4.3和4.4。除4.1.2外,所有工作都完美。由于4.0.3工作,4.1.2在技术上也应该这样,所以我无法弄清楚出了什么问题。

这是我的activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
tools:context="-removed name-">


<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- FrameLayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- ListView to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background" />
</android.support.v4.widget.DrawerLayout>
</FrameLayout>

这是我的fragment_layout.xml:

 <RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

 <Spinner
 android:layout_width="match_parent"
 android:layout_height="48dp"
 android:id="@+id/spinner_convertFrom"
 android:spinnerMode="dialog"
 android:layout_marginLeft="16dp"
 android:layout_marginRight="4dp"
 android:layout_alignRight="@+id/button"
 android:layout_alignTop="@+id/spinner_convertTo" />

<Spinner
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/spinner_convertTo"
android:spinnerMode="dialog"
android:layout_marginRight="16dp"
android:layout_marginLeft="4dp"
android:layout_alignLeft="@+id/button"
android:layout_marginTop="90dp" />

<EditText
android:layout_width="wrap_content"
android:layout_height="48dp"
android:inputType="numberDecimal|numberSigned"
android:ems="10"
android:id="@+id/editText_convert"
android:gravity="center"
android:imeOptions="actionDone"
android:selectAllOnFocus="true"
android:layout_marginBottom="30dp"
android:layout_above="@+id/button_Convert"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="@string/convert_button"
android:id="@+id/button_Convert"
android:clickable="true"
android:gravity="center"
android:layout_marginBottom="40dp"
android:layout_above="@+id/textView_result"
android:layout_centerHorizontal="true"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/convert_from"
android:id="@+id/textView_convertFrom"
android:textSize="14sp"
android:layout_alignLeft="@+id/spinner_convertFrom"
android:layout_marginBottom="8dp"
android:layout_alignTop="@+id/textView_ConvertTo" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/convert_to"
android:id="@+id/textView_ConvertTo"
android:textSize="14sp"
android:layout_alignLeft="@+id/spinner_convertTo"
android:layout_marginTop="74dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="120dp"
android:text="@string/result_box"
android:id="@+id/textView_result"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center"
android:singleLine="false"
android:textIsSelectable="true"
android:background="@drawable/result_border" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/button"
android:layout_centerHorizontal="true" />

</RelativeLayout>

我搜索了所有类似的问题,但他们的解决方案对我不起作用。

完整日志:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{-removed name-/-removed name-.MainActivity}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: 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:5616)
        at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1809)
        at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1721)
        at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2784)
        at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
        at android.app.Activity.setContentView(Activity.java:1867)
        at -removed name-.MainActivity.onCreate(MainActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

整个logcat没有发布。剩下的就是:

at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Styles.xml:

<resources xmlns:tools="http://schemas.android.com/tools">

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:popupMenuStyle">@style/PopupMenu.Konvertr</item>
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Konvertr</item>
    <item name="android:windowBackground">@color/window_bg</item>
    <item name="android:windowTranslucentNavigation" tools:targetApi="19">true</item>
    <item name="android:dropDownSpinnerStyle">@style/SpinnerAppTheme</item>
</style>

<style name="ActionBar.Solid.Konvertr" parent="@android:style/Widget.Holo.ActionBar.Solid">
    <item name="android:background">@drawable/ab_background_textured_konvertr</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_konvertr</item>
    <item name="android:backgroundSplit">@drawable/ab_background_textured_konvertr</item>
</style>

<style name="ActionBar.Transparent.Konvertr" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/ab_transparent_konvertr</item>
</style>

<style name="PopupMenu.Konvertr" parent="@android:style/Widget.Holo.ListPopupWindow">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_konvertr</item>
</style>

<style name="SpinnerAppTheme" parent="@android:Widget.Holo.Spinner">
    <item name="android:background">@drawable/apptheme_spinner_background_holo_dark</item>
</style>

2 个答案:

答案 0 :(得分:33)

您应该以{{1​​}}样式添加android:windowTranslucentNavigation属性。

旧版本不支持。

答案 1 :(得分:4)

虽然有很多属性可能导致此崩溃,但由于很难修复,您可能只想检查?android:attr/listPreferredItemPaddingStart(以及所有其他~start和~endore属性)。 This question也表示windowTranslucentStatuswindowTranslucentNavigation是个问题。