所以我的问题有点奇怪。我一直收到这个错误提示:
奇怪的是这只在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:
这是我的fragment_layout.xml文件内容:
整个logcat没有发布。以下是剩余部分:
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>