2

Hi I am developing application .My application run perfectly on all devices.But when we run this application on mdpi phone its getting me this error:

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

Kindly help me where i am wrong.

This is My Code:-

<RelativeLayout
    android:id="@+id/LevLayId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="140dp" >

    <TextView
        android:id="@+id/totlScorId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:background="@drawable/score_timer"
        android:gravity="center"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/levelId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/score_timer"
        android:gravity="center"
        android:textColor="#ffffff" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/LayAboButId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/option_last_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="7px"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/opt3Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal_new"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />

        <Button
            android:id="@+id/opt4Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/option_pre_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/option_last_row"
        android:layout_marginBottom="3px"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/opt1Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal_new"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />

        <Button
            android:id="@+id/opt2Btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/option_normal"
            android:gravity="center|center_vertical"
            android:textColor="#ffffff"
            android:textSize="11dp" />
    </LinearLayout>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/imgLayId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="70dp"
    android:layout_marginRight="@id/totlScorId"
    android:layout_marginTop="70dp" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/imgViewId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <ImageView
        android:id="@+id/imgViewframeId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/photo_frame" />
</RelativeLayout>

chancyWu
  • 14,073
  • 11
  • 62
  • 81
Rishabh Agrawal
  • 861
  • 2
  • 15
  • 25
  • @Rishabh.CreatioSoft Use one Parent Layout. – Dipak Keshariya Nov 29 '12 at 13:06
  • possible duplicate of [java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12](http://stackoverflow.com/questions/21822523/java-lang-unsupportedoperationexception-cant-convert-to-dimension-type-0x12) – nmr Dec 09 '14 at 23:29

2 Answers2

2

Use one Parent layout and Use below XML code instead of your code, it will solve your problem.

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

    <RelativeLayout
        android:id="@+id/LevLayId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="140dp" >

        <TextView
            android:id="@+id/totlScorId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/score_timer"
            android:gravity="center"
            android:textColor="#ffffff" />

        <TextView
            android:id="@+id/levelId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/score_timer"
            android:gravity="center"
            android:textColor="#ffffff" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/LayAboButId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/option_last_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="7px"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/opt3Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal_new"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />

            <Button
                android:id="@+id/opt4Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/option_pre_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/option_last_row"
            android:layout_marginBottom="3px"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/opt1Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal_new"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />

            <Button
                android:id="@+id/opt2Btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/option_normal"
                android:gravity="center|center_vertical"
                android:textColor="#ffffff"
                android:textSize="11dp" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/imgLayId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:layout_marginRight="@id/totlScorId"
        android:layout_marginTop="70dp" >

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <ImageView
            android:id="@+id/imgViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />

        <ImageView
            android:id="@+id/imgViewframeId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/photo_frame" />
    </RelativeLayout>

</RelativeLayout>
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
  • I am getting a similar error. any idea why it is happening only on HTC phones http://stackoverflow.com/questions/14454024/android-app-crashes-on-htc-and-sony-ericsson-phone – Harsha M V Jan 22 '13 at 17:30
  • 4
    Could you please also say exactly which lines are the problem? No one wants to have to read these line by line to figure it out. Thanks. – Craig B Apr 02 '14 at 15:24
0

Just started getting this today, so spotted the change which led to it. In my case, it was because I've had to create a new layout directory layout-xhdpi for a new device. Now, the new device thinks it's "large" (ie. it was using the layouts in layout-large); but it's really xhdpi.

So in the new layout xml, file I added reference to a value from a values-large/dimens.xml

However, this doesn't work.

Creating values-xhdpi/dimens.xml with the referenced value in it, solved the problem.

TL;DR make sure that you have a values-XXXXX directories for each layout-XXXXX directory, and that all relevant values are in there. I believe that values applicable to all sizes will be found in values/dimens.xml, but that's not how my app is structured, so I can't prove it.

user3660664
  • 237
  • 3
  • 8
  • Android display 'size' (e.g. "large") is orthogonal to display density. I.e. you can have an xhdpi screen which is size large, and an xhdpi screen which is size medium. Also, there are resource qualifier priority rules that explain the behavior you saw. – nmr Dec 08 '14 at 23:46