【问题标题】:Weird crash report : Binary XML file line #26: Binary XML file line #26奇怪的崩溃报告:二进制 XML 文件第 26 行:二进制 XML 文件第 26 行
【发布时间】:2017-08-17 13:04:06
【问题描述】:

请帮助我解决此崩溃报告无法确定发生这种情况的原因。它只发生在联想手机上,适用于所有其他手机。

STACK_TRACE = java.lang.RuntimeException:无法启动活动 ComponentInfo{com.somenewapp/com.somenewapp.CategoryActivity}:android.view.InflateException:二进制 XML 文件第 26 行:二进制 XML 文件第 26 行:膨胀错误类在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2560) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app。 ActivityThread$H.handleMessage(ActivityThread.java:1475) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main (ActivityThread.java:5740) 在 java.lang.reflect.Method.invoke(Native Method) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 在 com.android.internal.os .ZygoteInit.main(ZygoteInit.java:766) 原因:android.view.InflateException:二进制 XML 文件第 26 行:二进制 XML 文件第 26 行:膨胀类时出错com.somenewapp.CategoryActivity.onCreate(CategoryActivity.java:30) 在 android.app.Activity.performCreate(Activity.java:6543) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 在 android.app.ActivityThread .performLaunchActivity(ActivityThread.java:2513) ... 9 更多 android.view.InflateException:二进制 XML 文件第 26 行:二进制 XML 文件第 26 行:com.somenewapp.CategoryActivity.onCreate(CategoryActivity.java: 30) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2513) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 在 android.app.Activity.performCreate(Activity.java:6543)。 app.ActivityThread.handleLaunchActivity(ActivityThread.java:2626) 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475) 在 android.os.Handler。 dispatchMessage(Handler.java:111) 在 android.os.Looper.loop(Looper.java:207) 在 android .app.ActivityThread.main(ActivityThread.java:5740) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com .android.internal.os.ZygoteInit.main(ZygoteInit.java:766)

这是我的 onCreate 方法。

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT > 20) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
        window.setStatusBarColor(Color.BLACK);
    }

    setContentView(R.layout.activity_category); //this is line 30

}

这是我的activity_category.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/india_bg"
    tools:context="com.somenewapp.CategoryActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/content_description"
        android:src="@color/transparent_green"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginEnd="@dimen/large_marg"
        android:layout_marginLeft="@dimen/large_marg"
        android:layout_marginRight="@dimen/large_marg"
        android:layout_marginStart="@dimen/large_marg"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/content_description"
      android:src="@drawable/india_1024"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/narr_marg"
            android:contentDescription="@string/content_description"
            android:src="@drawable/import_yarn_from_india_1024"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_marginEnd="@dimen/narr_marg"
            android:layout_marginLeft="@dimen/narr_marg"
            android:layout_marginRight="@dimen/narr_marg"
            android:layout_marginStart="@dimen/narr_marg"
            android:layout_marginTop="@dimen/narr_marg"
            android:background="@color/aluminum"
            />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/narr_marg"
            android:contentDescription="@string/content_description"
      android:src="@drawable/indian_flag_1947"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"
            />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/narr_marg"
            android:contentDescription="@string/content_description"
      android:src="@drawable/indian_flag"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_marginEnd="@dimen/narr_marg"
            android:layout_marginLeft="@dimen/narr_marg"
            android:layout_marginRight="@dimen/narr_marg"
            android:layout_marginStart="@dimen/narr_marg"
            android:layout_marginTop="@dimen/narr_marg"
            android:background="@color/aluminum"
            />
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/narr_marg"
            android:contentDescription="@string/content_description"
      android:src="@drawable/india_new_sec"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"/>
    </LinearLayout>
</RelativeLayout>

【问题讨论】:

  • 您确定这是联想手机的问题,而不是您正在测试的设备的 API 版本吗?
  • 是的,我确信这不是特定于 API 版本的问题,因为我已经在 API 级别 17 到 25 上进行了测试。代码运行良好。

标签: java android xml android-layout


【解决方案1】:

显然错误是布局的第26行,对应这个ImageView

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/content_description"
  android:src="@drawable/india_1024"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"/>

我最好的选择是 drawable india_1024 有某种资源限定符导致它失败,或者是一个巨大的图像导致这个设备因为内存不足而失败。应该是前者。

您能否添加有关此可绘制对象的更多信息?

【讨论】:

  • india_1024 drawable 具有规格分辨率:1024* 240 并且只有 37kb
  • 您可以访问该设备吗?如果是这样,最好删除此 ImageView 以查看它是否真的是罪魁祸首。考虑到压缩图像的大小无关紧要,重要的是图像的未压缩大小。另外,您使用的是 adjustViewBounds="true",这意味着它可能会扩展(在 API 17 或更高版本上,我认为这是您的情况)。
  • 实际上,我收到了崩溃报告,无法在其他设备上重新创建它。一切正常,即使我已经在 android 监视器上跟踪它,内存使用量也不多。请有其他建议。
  • 如果没有设备验证,我建议的任何内容都将无济于事。布局看起来很正常,所以我上面所说的是我对可能导致问题的唯一想法。我建议您找到确切的型号并尝试通过朋友、家人、购买来访问某个设备……或者尝试查看在线设备农场中是否有此型号可用:testobject.comkobiton.com aws.amazon.com/es/device-farmfirebase.google.com/docs/test-lab
猜你喜欢
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-13
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多