【发布时间】: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