5

We launched the app on the Market today - Nomad. I am getting reports that the app crashes on HTC and Sony Ericsson Phones. I got the following Log report from one of the USER.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.m7.nomad/com.m7.nomad.SplashActivity}: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x3
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x3
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5459)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1776)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1700)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:56)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
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:2707)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2767)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:247)
at android.app.Activity.setContentView(Activity.java:1835)
at com.m7.nomad.SplashActivity.onCreate(SplashActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more

Not able to understand why it happens.

SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;

    // Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_splash);

    // Shared Preferences
    settings = getSharedPreferences(SETTINGS_PREFS, 0);

    configRun = settings.getInt("database_version", 0);

    this.assetManager = this.getAssets();


}

Line 46 points to setContentView(R.layout.activity_splash);

activity_splash.java

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="Splash Screen"
        android:gravity="center"
        android:src="@drawable/splash_logo" />

</RelativeLayout>
Harsha M V
  • 54,075
  • 125
  • 354
  • 529

3 Answers3

2

The cause of your crash is likely tucked away in your styles. It likely contains an attribute referencing a dimension contained within the Android SDK, whereas you are running your application on an older version of the SDK that does not contain that dimension.

In this example, the author used the following attribute:

android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"

However, as the accepted answer points out, the listPreferredItemPaddingLeft entry in android.R.attr is only available from SDK level 14 onwards.

Either remove the offending entries, replace them, or separate the resource files such that they respect the SDK level. For instance, you could provide one style in res/values-14, and another omitting those entries from the version in res/values.

Community
  • 1
  • 1
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • removing them just worked fine and didnt change anything so we have done that for now. thanks for pointing out how to accommodate the same using value-14. i will try that and let you know :D – Harsha M V Apr 07 '13 at 18:33
1

Apply this xml in your project and see what happens :)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/primary_color"
    android:textAlignment="center" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="Splash Screen"
        android:gravity="center"
        android:src="@drawable/splash_logo" />

</RelativeLayout>

Comment this line ::

context = this;
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
AndroidLearner
  • 4,500
  • 4
  • 31
  • 62
1

Use this in your splash layout

<?xml version="1.0" encoding="utf-8"?>
 <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5492a"
android:contentDescription="Splash Screen"
android:scaleType="fitCenter"
android:src="@drawable/splash_logo" >

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
  • why cant i use a layout ? i need to fill a background color – Harsha M V Jan 22 '13 at 09:58
  • you can use `android:background="@color/primary_color"` if you like, BTW same color. :) – M-Wajeeh Jan 22 '13 at 10:00
  • any idea why it is happening ??? i mean why does it happen only on HTC. i dont have a htc at my disposal. getting it checked from a friend :D – Harsha M V Jan 22 '13 at 10:01
  • I guess `android:textAlignment="center"` is buggy on HTC devices, just a guess.... ;) – M-Wajeeh Jan 22 '13 at 10:13
  • Here is a hint, launch your AboutActivity or MainActivity instead of SplashActivity. If it still crashes then the problem is with your theme, remove this tag `android:theme="@style/Theme.Nomad"` from your manifest and it will surely work. If it works then you will know where to look. – M-Wajeeh Jan 23 '13 at 09:25
  • I was right :P Problem is here `@drawable/ic_menu_share` in your theme. ;) – M-Wajeeh Jan 23 '13 at 09:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23204/discussion-between-m-wajeeh-and-harsha-m-v) – M-Wajeeh Jan 23 '13 at 09:54