5

My XML file

<?xml version="1.0" encoding="utf-8"?>
<com.trill.trillapp.customviews.TrillSocialNetworkBar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/social_network"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_social_network_bar_height"
    android:background="@color/color01">

    <ImageView
        android:id="@+id/social_facebook_bt"
        android:layout_width="90dp"
        android:layout_height="match_parent"
        android:src="@drawable/button_like_off" />

    <com.trill.trillapp.customviews.TrillNotificationTextView
        android:id="@+id/social_facebook_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/social_facebook_bt"
        android:layout_marginLeft="@dimen/detail_social_text_margin_left"
        android:layout_marginTop="@dimen/detail_social_bar_icon_margin"
        android:gravity="center"
        android:text="9"
        android:textColor="@color/color01"
        android:textSize="@dimen/font_f14" />

    <ImageView
        android:id="@+id/social_twitter_bt"
        android:layout_width="90dp"
        android:layout_height="match_parent"
        android:layout_toRightOf="@+id/social_facebook_bt"
        android:scaleType="center"
        android:src="@drawable/icon_sns_tw" />

    <com.trill.trillapp.customviews.TrillNotificationTextView
        android:id="@+id/social_twitter_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/social_twitter_bt"
        android:layout_marginLeft="@dimen/detail_social_text_margin_left"
        android:layout_marginTop="@dimen/detail_social_bar_icon_margin"
        android:gravity="center"
        android:maxLength="3"
        android:ellipsize="end"
        android:text="0"
        android:textColor="@color/color01"
        android:textSize="@dimen/font_f14" />

    <ImageView
        android:id="@+id/social_line_bt"
        android:layout_width="90dp"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/social_share"
        android:scaleType="center"
        android:src="@drawable/icon_sns_line" />

    <com.trill.trillapp.customviews.TrillNotificationTextView
        android:id="@+id/social_line_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/social_line_bt"
        android:layout_marginLeft="@dimen/detail_social_text_margin_left"
        android:layout_marginTop="@dimen/detail_social_bar_icon_margin"
        android:gravity="center"
        android:text="0"
        android:textColor="@color/color01"
        android:textSize="@dimen/font_f14" />

    <ImageView
        android:id="@+id/social_share"
        android:layout_width="90dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:scaleType="center"
        android:src="@drawable/icon_share_off" />

</com.trill.trillapp.customviews.TrillSocialNetworkBar>

I got following error when inflating this layout:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trill.trillapp/com.trill.trillapp.activities.TrillDetailArticle}: 
java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1

How to fix it?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Owlery
  • 171
  • 1
  • 1
  • 8

2 Answers2

10

I've found that i lack of value in dimens.xml file. So it cause error

Owlery
  • 171
  • 1
  • 1
  • 8
6

As with all android resources, dimensions are stored in various qualified values.

values\dimens.xml
values-v21\dimens.xml
values-land\dimens.xml

It may be that the dimension is available in some, but not all necessary locations.

The easiest fix for this problem, is to add an entry into values\dimens.xml which is the fall-back place if any of the specifics fail.

mksteve
  • 12,614
  • 3
  • 28
  • 50
  • Yes this is true, I also faced a same situation, and the solution was declaring the missing dimension value in the values/dimens.xml file. – maxxi Feb 28 '18 at 04:24