Android Inflateexception / OutOfMemory

时间:2015-06-30 12:12:53

标签: android

我正在开发Android应用程序,整个应用程序运行正常,直到我尝试在主要活动之前添加Splashscreen。我的主要活动包括右侧的设置抽屉,导致应用程序因其背景图像而崩溃。删除此背景图像时,应用程序可以使用闪屏运行正常。从Splashscreen导航到Main活动时发生崩溃。

启动画面也包含两个图像,删除启动画面的背景图像也使应用程序再次运行正常。因此,我试图将图像的大小减小到不超过78kb和17kb的程度,但即使使用这些大小,它也会给我inflateexception / OutOfMemory。希望有人知道解决方案,因为我确实需要设置抽屉的闪屏和背景图像。

错误:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.myApp.myApp/nl.myApp.tabs.agenda.AgendaActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
    at android.app.ActivityThread.access$900(ActivityThread.java:182)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6141)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:640)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    at nl.myApp.drawerNavigation.SettingsDrawer.onCreateView(SettingsDrawer.java:43)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:838)
    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:826)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at nl.myApp.tabs.agenda.AgendaActivity.onCreate(AgendaActivity.java:15)
    at android.app.Activity.performCreate(Activity.java:6374)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
    at android.app.ActivityThread.access$900(ActivityThread.java:182)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6141)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
    at android.view.LayoutInflater.createView(LayoutInflater.java:614)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    at nl.myApp.drawerNavigation.SettingsDrawer.onCreateView(SettingsDrawer.java:43)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
    at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:838)
    at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:34)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:826)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
    at nl.myApp.tabs.agenda.AgendaActivity.onCreate(AgendaActivity.java:15)
    at android.app.Activity.performCreate(Activity.java:6374)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2767)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2879)
    at android.app.ActivityThread.access$900(ActivityThread.java:182)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6141)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 64032012 byte allocation with 16777216 free bytes and 36MB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:816)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:63

Splashscreen XML:

    <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"
tools:context=".Splashscreen">

<ImageView
    android:id="@+id/splashscreen_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/splashscreen_night2"/>

<ImageView
    android:id="@+id/splashscreen_logo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="64dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/logo_night"/>

    </RelativeLayout>

设置抽屉XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="nl.myApp.drawerNavigation.SettingsDrawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_sidemenu_blur" >

        <!-- Content -->

    </RelativeLayout>

0 个答案:

没有答案