无法分配带有11873648个空闲字节的12845068字节分配和直到OOM的11MB

时间:2017-04-04 07:37:46

标签: android

我在项目中遇到过这个问题。我从堆栈溢出中搜索了答案,其中一些人给出了这个问题的解决方案"android:largeHeap="true",android:hardwareAccelerated="false",我在清单文件中尝试了这两行,但即使我遇到同样的问题。

但有一件事我不得不说这个问题只在Nexus 6中提出......剩下的设备nexus 5正常运行

com.example.sit.mobileappmaker E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.sit.mobileappmaker, PID: 20509 java.lang.OutOfMemoryError: Failed to allocate a 12845068 byte allocation with 11873648 free bytes and 11MB 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.view.View.<init>(View.java:3954)
    at android.widget.ImageView.<init>(ImageView.java:145)
    at android.widget.ImageButton.<init>(ImageButton.java:84)
    at android.widget.ImageButton.<init>(ImageButton.java:80)
    at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:60)
    at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56)
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
    at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1021)
    at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1080)
    at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
    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.rInflate(LayoutInflater.java:838)
    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.rInflate(LayoutInflater.java:838)
    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.rInflate(LayoutInflater.java:838)
    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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.sit.mobileappmaker.MobileAppMaker.Templetes.ClassicMenu.onCreate(ClassicMenu.java:118)
    at android.app.Activity.performCreate(Activity.java:6251)
    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)

1 个答案:

答案 0 :(得分:0)

您的图片太大而无法加载。 试试这个:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;//SCALE SIZE
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, options);

不要在布局xml中设置你的drawable。