Android应用程序崩溃的HTC和索尼爱立信手机(Android App Crashes on H

2019-08-07 18:11发布

我们今天推出的市场应用- 游牧 。 我得到的报告,该应用程序崩溃,在HTC和索尼爱立信手机。 我从用户的一个得到了下面的日志报告。

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

无法理解为什么会发生。

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();


}

线46分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>

Answer 1:

在飞溅的布局使用此

<?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" >



Answer 2:

你的飞机坠毁的原因在你的风格很可能藏身。 它有可能包含引用包含在Android SDK中的一个维度的属性,而你正在运行您的旧版本不包含该维度的SDK的应用。

在这个例子中 ,笔者使用了以下属性:

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

然而,由于接受的答案指出, listPreferredItemPaddingLeft条目中android.R.attr只能从SDK级别14起。

要么删除有问题的条目,替换它们,或分开的资源文件,他们尊重的SDK水平。 例如,你可以在一个提供风格res/values-14 ,另一个忽略从版本这些条目res/values



Answer 3:

在项目中应用此XML和看看会发生什么:)

<?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>

评论此行::

context = this;
this.requestWindowFeature(Window.FEATURE_NO_TITLE);


文章来源: Android App Crashes on HTC and Sony Ericsson Phone