Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1

爱⌒轻易说出口 提交于 2019-11-26 17:32:43

After 2 days I found the solution; from the layout as defined in my question, I have a Spinner which is bound with a custom TextView:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listTextViewSpinner"
    ...
    android:textSize="@dimen/spinner_list_item_text_size"
    ... />

Here, I have an extracted dimension resource: @dimen/spinner_list_item_text_size.

This has been defined in dimens.xml in the following directories:

  • values-sw600dp
  • values-sw720dp-land

but crucially I forgot to define it in

  • values

After defining the resource (@dimen/spinner_list_item_text_size) in values/dimens.xml,it works successfully.

I my case the problem was

<dimen name="name">12</dimen>

instead of:

<dimen name="name">12dp</dimen>
Olllli

You find in your logcat before the exception a line like this:

08-19 10:05:58.008: W/ResourceType(3999): Failure getting entry for 0x7f0a005f (t=9 e=95) in package 0 (error -75)

Search for tis number (here 0x7f0a005f) in the generated Resource.class R.java. The name of the variable is the missing dimen-resource.

For others that get here from a Google search, make sure you're assigning a dimension instead of something else. The logcat will point you to the problem view.

i.e. Somehow, 1 of my layouts had a couple of TextViews with android:textSize="?android:attr/textAppearanceSmall"

Renamed them to android:textAppearance="?android:attr/textAppearanceSmall" and all is well again.

Solved: I had the same error, But it turns out i forgot to define a value in dimens.xml yet i had defined it in dimens.xml(w820dp). Make sure all the values are defined. Worked for me

You can have a look to this thread, the problem seems to be exactly the one you're having:

https://github.com/JakeWharton/ActionBarSherlock/issues/446

It seems the trick is to do the following:

I met the same problem today, i couldn't find the reason but finally got a solution. It seems that you cannot put any properties that M9 cannot recognize int theme.xml, just like android:actionBarStyle. So the solution is to make a new theme.xml in value-v14, and put all these properties in it.

Good luck!

For me the problem was the value in the dimension.

<dimen name="general_container_width">@dimen/match_parent</dimen>

android was not able to resolve the @dimen/match_parent when I was trying to get the value in my custom view.

just add in root tools:ignore="ContentDescription"

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="ContentDescription" >

And for me it was a bad styles.xml that defined a textSize incorrectly:-

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:gravity">center</item>
        <item name="android:textSize">@style/TextAppearance.AppCompat.Small</item>
    </style>

    ...
</resources>

The hint came from the following stack trace and realizing that the above was one of the size related changes I made since last successful run.

 Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
                                                                      at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:464)
                                                                      at android.widget.TextView.<init>(TextView.java:972)
                                                                      at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
                                                                      at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
                                                                      at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:54)
                                                                      at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:756)
                                                                      at android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
                                                                      at android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
                                                                      at android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:615)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:636)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:333)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.edsglobal.ecbc.AMAinActivity.onCreate(AMAinActivity.java:94)
                                                                      at android.app.Activity.performCreate(Activity.java:5231)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:136) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5017) 
                                                                      at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                      at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                                                                      at dalvik.system.NativeStart.main(Native Method) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!