Can't convert to dimension: type=0x1 when running app on Android 4.1

simekadam picture simekadam · Jun 30, 2013 · Viewed 10k times · Source

I recently started to use genymotion instead of classic Android virtual device, but I have some issues with it.. When I try to run my app I got this error.

Can't convert to dimension: type=0x1

I comes from LayoutInflater..When I run it in Genymotion it says that there is some layout param which has bad type..below are two screenshots from android studio. The first has been taken when running the app on Nexus 4 and the second one is from Genymotion. this one has been taken while I've been testing the app on Nexus 4

this one has been taken while running on Genymotion virtual device

Both should be running Jelly Bean, the only difference is that Genymotion is on API 16, while Nexus 4 runs up to date on 4.2.2, thus API 17..

The problems comes from my custom list view adapter - from its getView method, so I think it must be related to one of those layouts. (I have two different types of list items)

list_heading.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">


<TextView
        android:id="@+id/listViewHeaderText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingTop="10dp"
        android:paddingBottom="3dp"
        android:text="Nacionále"
        android:textAppearance="?android:attr/listSeparatorTextViewStyle"
        android:textColor="@color/main_cvut"/>


<RelativeLayout
        android:id="@+id/listViewHeaderLine"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="@color/main_cvut"/>
</LinearLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/listItem"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/list_item_layout"
            android:clickable="true"
            android:focusable="true"
            android:paddingTop="?android:attr/listPreferredItemPaddingStart"
            android:minHeight="?android:attr/listPreferredItemHeight">

<TextView
        android:id="@+id/itemTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:paddingRight="?android:attr/listPreferredItemPaddingRight"
        android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
        android:textAppearance="?android:attr/textAppearanceMedium"/>

<TextView
        android:id="@+id/itemDescription"
        android:textColor="@android:color/darker_gray"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="description"
        android:paddingRight="?android:attr/listPreferredItemPaddingRight"
        android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
        android:textAllCaps="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_marginBottom="?android:attr/listPreferredItemPaddingEnd"
        android:paddingBottom="?android:attr/listPreferredItemPaddingRight"
        android:layout_below="@+id/itemTitle"/>

<ImageView
        android:id="@+id/itemIcon"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="16dp"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true"/>

<RelativeLayout
        android:id="@+id/itemBottomLine"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="?android:attr/listPreferredItemPaddingEnd"
        android:background="#b5b5b5"
        android:layout_alignParentEnd="false"/>
</RelativeLayout>

I tried to delete all of those referenced paddings, margins,.. But it has had no effect at ll.. I also tried to run it in standard android emulator with API 16 and it also does not work..Please could you tell me which part of this code is not compatible with that version?

Answer

Nipper picture Nipper · Jul 8, 2013

Always look at the API Level for an attribute:

<RelativeLayout
    ...
    ...
    android:layout_alignParentEnd="false"/>

android:layout_alignParentEnd was added in API level 17

http://developer.android.com/reference/android/widget/RelativeLayout.html#ALIGN_PARENT_END