更改布局中的背景和图像视图时出现内存不足错误?

时间:2019-04-17 05:36:11

标签: out-of-memory android-drawable

我是第一次设计我的应用程序,并且在可绘制文件夹中,我的背景图像分辨率为1080 * 2560,大小为200 KB,还有一些图标,我在图像视图中设置的分辨率为500 * 500,分辨率为12 KB至15 KB大小和PNG格式。

当我在应用程序的布局中设置这些设置时,我会失去内存异常,因为存在多个活动,并且在更改设计时设置这些可绘制对象在每个活动中都给我OOM错误。

在对背景和图像视图进行更改后,我还要提到3到4个android设备,它工作正常,但在2个设备中却给我OOM错误。

这是错误

/AndroidRuntime: FATAL EXCEPTION: main
Process: com.intrusoft.sectionedrecyclerviewapp, PID: 22558
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intrusoft.sectionedrecyclerviewapp/com.intrusoft.sectionedrecyclerviewapp.StartActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class <unknown>
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
    at android.app.ActivityThread.access$1100(ActivityThread.java:222)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7237)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class <unknown>
    at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at com.intrusoft.sectionedrecyclerviewapp.StartActivity.onCreate(StartActivity.java:42)
    at android.app.Activity.performCreate(Activity.java:6876)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:158) 
    at android.app.ActivityThread.main(ActivityThread.java:7237) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
 Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:657)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.intrusoft.sectionedrecyclerviewapp.StartActivity.onCreate(StartActivity.java:42) 
    at android.app.Activity.performCreate(Activity.java:6876) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:158) 
    at android.app.ActivityThread.main(ActivityThread.java:7237) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at android.view.LayoutInflater.createView(LayoutInflater.java:631)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:855) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
    at com.intrusoft.sectionedrecyclerviewapp.StartActivity.onCreate(StartActivity.java:42) 
    at android.app.Activity.performCreate(Activity.java:6876) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:158) 
    at android.app.ActivityThread.main(ActivityThread.java:7237) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 101606412 byte allocation with 16765280 free bytes and 59MB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675)
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228)
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:4215)
    at android.content.res.Resources.loadDrawable(Resources.java:4089)
    at android.content.res.Resources.loadDrawable(Resources.java:3939)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
    at android.view.View.<init>(View.java:4230)
    at android.view.ViewGroup.<init>(ViewGroup.java:589)
    at android.widget.LinearLayout.<init>(LinearLayout.java:202)
    at android.widget.LinearLayout.<init>(LinearLayout.java:198)

0 个答案:

没有答案