gpt4 book ai didi

调用 getDrawable() 时出现 java.lang.OutOfMemoryError

转载 作者:行者123 更新时间:2023-12-02 12:00:29 24 4
gpt4 key购买 nike

我收到以下内存不足错误,但我不确定原因。

Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM

java.lang.OutOfMemoryError: Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037)

at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.graphics.drawable.LevelListDrawable.inflate(LevelListDrawable.java:128)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4045)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.content.Context.getDrawable(Context.java:409)
at com.MyCompany.MyApp.Login.updateWifiStatus(Login.java:942)
at com.MyCompany.MyApp.Login$6.run(Login.java:576)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

我正在使用 5 级资源来指示 wifi 状态,这是我正在使用的代码

    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

// Level of current connection
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
Drawable db = getDrawable(R.drawable.stat_sys_wifi_signal);
db.setLevel(level);
wifiMenu.setIcon(db);

图像尺寸均相同 (512x512)。

引用其他答案,我的 list 中有largeheap。

任何帮助将不胜感激。

最佳答案

Use TinyPNG

TinyPNG uses smart lossy compression techniques to reduce the file size of your PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!

使用此链接压缩所有图像。

在 Android 应用程序中使用之前减小所有图片的大小。

请务必阅读文档 Loading Large Bitmaps Efficiently由@mudit_sen 给出。

希望这对您有帮助。

关于调用 getDrawable() 时出现 java.lang.OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47284227/

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