问题描述
实际上,我正在尝试创建一个包含n个多媒体文件的应用程序,其中包括图像和视频。我的应用大小约为 34MB
,我的资产大小约为 60mb
。当我在正常设备上加载应用程序时,我们没有遇到任何问题,但设备 2K分辨率
,例如 Nexus 6P,HTC,LG
等,应用程序在进程中间崩溃并出现Out Of Memory错误。
我用这个产生了错误报告。我也尝试过位图工厂。
同时我在数组方法中使用视频。
Actually, I am trying to create a app with n number of multimedia files which includes images and videos. My apps size is around 34MB
, and my assets size is around 60mb
. While I am loading the app in normal devices we are not facing any problem, But the devices having 2K resolutions
such as Nexus 6P, HTC, LG
etc., the apps get crash in the middle of the process with the error "Out Of Memory".I have produced the error report with this. I have tried to bitmap factory also.At the same time I am using videos in array method.
任何人都可以帮忙解决这个问题吗?
Can anyone help with this issue?
java.lang.OutOfMemoryError:失败在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java)的android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)的dalvik.system.VMRuntime.newNonMovableArray(Native Method)中分配一个1660396字节分配1243880个空闲字节和1214KB直到OOM。 620)在Android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)android.content.resable.Drawable.createFromResourceStream(Drawable.java:1155)android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) )android.content.res.Resources上的android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)android.content.res.Resources.loadDrawable(Resources.java:858)android.content.res.TypedArray.getDrawable(TypedArray.java: 92 8)在android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java)的android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:297)的android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:327) :130)android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)在android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl。)的android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)。 java:715)在android.content.res.Resources上的android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)android.content.getDrawable(Context.java:771) :525)在android.app.A活动时,我在android.app.A活动中调用了android.view.k.Met上的com.example.kq.meettheshps.Score_Card.onCreate(Score_Card.java:58)的android.view.View.setBackgroundResource(View.java:18228)(Activity.java: 6679)在android.app.ActivityThread.perfo的android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) rmLaunchActivity(ActivityThread.java:2618)位于android.app.A活动中的android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726),android.app.ActivityThread $ H.handleMessage(ActivityThread。)的android.app.ActivityThread.-wrap12(ActivityThread.java)。 java:1477)在android.os.Handler.dispatchMessage(Handler.java:102)在android.app.Looper.loop(Looper.java:154)的android.app.ActivityThread.main(ActivityThread.java:6119)at java.lang.reflect.Method.invoke(Native Method)在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)com.android.internal.os.ZygoteInit.main(ZygoteInit.java) :776)
java.lang.OutOfMemoryError: Failed to allocate a 1660396 byte allocation with 1243880 free bytes and 1214KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.loadDrawable(Resources.java:858) at android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:327) at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:297) at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.getDrawable(Resources.java:771) at android.content.Context.getDrawable(Context.java:525) at android.view.View.setBackgroundResource(View.java:18228) at com.example.kq.meettheshps.Score_Card.onCreate(Score_Card.java:58) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
推荐答案
我找到的简单解决方案是,
添加 hardwareAccelerated
& largeHeap
应用程序
AndroidManifest.xml
Simple Solution which I found is,Add hardwareAccelerated
& largeHeap
under application
AndroidManifest.xml
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
这篇关于java.lang.OutOfMemoryError:在OOM之前分配分配失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!