android.view.InflateException:二进制XML文件行#55:二进制XML文件行#55:错误输出类<unknown>

时间:2017-01-20 15:25:03

标签: android-layout android-studio imageview android-linearlayout inflate-exception

我是新的android。

我正在为商用厨房设备供应商开发应用程序。我特别在一个部分遇到问题。此活动为products_1.xml布局资源文件。我创建了一个线性布局,产品为ImageView。 ImageView是可点击的。 LinearLayout中有12个这样的图像。该活动在具有较小显示设置(图标和文本)的手机上正常工作。但在具有正常显示或大显示屏的手机上,此活动有错误,应用程序崩溃。 Logcat在第55行显示错误,即ImageView android:id =“@ + id / Commercial_six”,当我将ImageView的图像src和下面的所有图像更改为前三个ImageView的图像时,应用程序运行正常。

所以我知道问题在于布局资源products_1.xml。

logcat的

01-20 09:42:43.018 7878-7878/com.example.aaron.imageapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: com.example.aaron.imageapp, PID: 7878
                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aaron.imageapp/com.example.aaron.imageapp.Product_1}: android.view.InflateException: Binary XML file line #55: Binary XML file line #55: Error inflating class <unknown>
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                       Caused by: android.view.InflateException: Binary XML file line #55: Binary XML file line #55: Error inflating class <unknown>
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
                                                                          at android.app.Activity.setContentView(Activity.java:2166)
                                                                          at com.example.aaron.imageapp.Product_1.onCreate(Product_1.java:19)
                                                                          at android.app.Activity.performCreate(Activity.java:6237)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                       Caused by: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                          at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                          at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                          at android.app.Activity.setContentView(Activity.java:2166) 
                                                                          at com.example.aaron.imageapp.Product_1.onCreate(Product_1.java:19) 
                                                                          at android.app.Activity.performCreate(Activity.java:6237) 
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                       Caused by: java.lang.reflect.InvocationTargetException
                                                                          at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                          at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                                          at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                          at android.app.Activity.setContentView(Activity.java:2166) 
                                                                          at com.example.aaron.imageapp.Product_1.onCreate(Product_1.java:19) 
                                                                          at android.app.Activity.performCreate(Activity.java:6237) 
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                       Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4632612 byte allocation with 2430288 free bytes and 2MB until OOM
                                                                          at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                          at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                          at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
                                                                          at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
                                                                          at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
                                                                          at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
                                                                          at android.content.res.Resources.loadDrawable(Resources.java:2540)
                                                                          at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
                                                                          at android.widget.ImageView.<init>(ImageView.java:152)
                                                                          at android.widget.ImageView.<init>(ImageView.java:140)
                                                                          at android.widget.ImageView.<init>(ImageView.java:136)
                                                                          at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                                          at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                                                                          at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                          at android.app.Activity.setContentView(Activity.java:2166) 
                                                                          at com.example.aaron.imageapp.Product_1.onCreate(Product_1.java:19) 
                                                                          at android.app.Activity.performCreate(Activity.java:6237) 
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                          at android.os.Looper.loop(Looper.java:148) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

product_1.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbarThumbVertical="@android:color/holo_orange_dark">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="#000000"
        android:orientation="vertical"
        android:weightSum="1">


        <ImageView
            android:id="@+id/Commercial_Chinese_Gas"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="60dp"
            android:src="@drawable/product_commercial_chinese_burner" />

        <ImageView
            android:id="@+id/Commercial_Single_Burner"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:layout_marginTop="0dp"
            android:src="@drawable/product_commercial_single_burner" />

        <ImageView
            android:id="@+id/Commercial_Two_Burner"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/product_commercial_two_burner" />

        <ImageView
            android:id="@+id/Commercial_four"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_four_burner_continental" />

        <ImageView
            android:id="@+id/Commercial_six"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_six_burner" />

        <ImageView
            android:id="@+id/Commercial_tilting_boiling"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_tilting_boiling_pan" />

        <ImageView
            android:id="@+id/Commercial_tilting_bratts"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_tilting_bratts" />

        <ImageView
            android:id="@+id/Commercial_mobile_tandoor"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_mobile_tandoor" />

        <ImageView
            android:id="@+id/Commercial_mobile_shwarma"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_shawerma" />

        <ImageView
            android:id="@+id/Commercial_mobile_automatic_chapatti_maker"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_automatic_chapati" />

        <ImageView
            android:id="@+id/Commercial_automatic_chapati_rolling"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_automatic_chapati_roling" />

        <ImageView
            android:id="@+id/Commercial_mobile_chapati_plate"
            android:layout_width="350dp"
            android:layout_height="350dp"
            android:layout_gravity="center"
            android:layout_marginBottom="50dp"
            android:src="@drawable/products_commercial_chapati_plate" />


    </LinearLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:0)

java.lang.OutOfMemoryError

您似乎正在使用具有高分辨率的图像,这会使您的应用崩溃。

使用回收站视图显示图像,而不要在同一页面中显示太多图像。