gpt4 book ai didi

android - 如何处理内存不足异常?

转载 作者:行者123 更新时间:2023-11-30 02:42:46 26 4
gpt4 key购买 nike

我为所有布局背景使用了 1920x1080 分辨率的图像。我得到了 OutOfMemory 异常。然后我在不同的文件夹中为不同的分辨率使用了不同的图像,但我仍然得到 OutOfMemory 异常。请任何人帮助我。下面是我的日志猫。

E/AndroidRuntime( 3997): FATAL EXCEPTION: main
E/AndroidRuntime( 3997): Process: com.pm.a, PID: 3997
E/AndroidRuntime( 3997): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pm.a/com.activities.services.ConfirmDetails}: android.view.InflateException: Binary XML file line #48: Error inflating class <unknown>
E/AndroidRuntime( 3997): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
E/AndroidRuntime( 3997): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
E/AndroidRuntime( 3997): at android.app.ActivityThread.access$900(ActivityThread.java:161)
E/AndroidRuntime( 3997): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
E/AndroidRuntime( 3997): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3997): at android.os.Looper.loop(Looper.java:157)
E/AndroidRuntime( 3997): at android.app.ActivityThread.main(ActivityThread.java:5356)
E/AndroidRuntime( 3997): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3997): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 3997): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
E/AndroidRuntime( 3997): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
E/AndroidRuntime( 3997): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3997): Caused by: android.view.InflateException: Binary XML file line #48: Error inflating class <unknown>
E/AndroidRuntime( 3997): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
E/AndroidRuntime( 3997): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
E/AndroidRuntime( 3997): at com.activities.services.ConfirmDetails.onCreate(ConfirmDetails.java:90)
E/AndroidRuntime( 3997): at android.app.Activity.performCreate(Activity.java:5426)
E/AndroidRuntime( 3997): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 3997): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
E/AndroidRuntime( 3997): ... 11 more
E/AndroidRuntime( 3997): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3997): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 3997): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
E/AndroidRuntime( 3997): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
E/AndroidRuntime( 3997): ... 26 more
E/AndroidRuntime( 3997): Caused by: java.lang.OutOfMemoryError
E/AndroidRuntime( 3997): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime( 3997): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
E/AndroidRuntime( 3997): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
E/AndroidRuntime( 3997): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
E/AndroidRuntime( 3997): at android.content.res.Resources.loadDrawable(Resources.java:3056)
E/AndroidRuntime( 3997): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
E/AndroidRuntime( 3997): at android.widget.ImageView.<init>(ImageView.java:133)
E/AndroidRuntime( 3997): at android.widget.ImageView.<init>(ImageView.java:123)
E/AndroidRuntime( 3997): ... 29 more
W/ActivityManager( 3050): Force finishing activity com.activities.services.ConfirmDetails

提前致谢。

最佳答案

OOM 错误是 a$$ 中的一个真正的痛苦。

您所能做的就是调整图像大小以降低质量和/或启用 largeHeap。

看看这个: Bitmap recycle with largeHeap enabled

关于android - 如何处理内存不足异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25520830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com