gpt4 book ai didi

java - Android 6.0 上的 Android java.lang.OutOfMemoryError

转载 作者:太空宇宙 更新时间:2023-11-04 11:39:11 26 4
gpt4 key购买 nike

所以我在 Play 商店上有这个应用程序,它可以帮助人们清理手机,并且我收到了一些错误消息,当人们单击“清理”按钮时,应用程序崩溃并且由于内存不足错误。这是错误消息:

java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 147468 byte allocation with 24512 free bytes and 23KB 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.getDrawable(Resources.java:2005)
at android.content.res.Resources.getDrawable(Resources.java:1987)
at android.app.ApplicationPackageManager.getDrawable(ApplicationPackageManager.java:977)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon(ApplicationPackageManager.java:2842)
at android.app.ApplicationPackageManager.loadItemIcon(ApplicationPackageManager.java:2774)
at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:220)
at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:206)
at panda.cleaner.cleaner_batterysaver.fragment.SoftwareManageFragment$1.doInBackground(SoftwareManageFragment.java:139)
at panda.cleaner.cleaner_batterysaver.fragment.SoftwareManageFragment$1.doInBackground(SoftwareManageFragment.java:127)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)

这是错误所在的类:

task = new AsyncTask<Void, Integer, List<AppInfo>>() {
private int mAppCount = 0;//(SoftwareManageFragment.java:127)

@Override
protected List<AppInfo> doInBackground(Void... params) {
PackageManager pm = mContext.getPackageManager();
List<PackageInfo> packInfos = pm.getInstalledPackages(0);
publishProgress(0, packInfos.size());
List<AppInfo> appinfos = new ArrayList<AppInfo>();
for (PackageInfo packInfo : packInfos) {
publishProgress(++mAppCount, packInfos.size());
final AppInfo appInfo = new AppInfo();
Drawable appIcon = packInfo.applicationInfo.loadIcon(pm);//(SoftwareManageFragment.java:139)
appInfo.setAppIcon(appIcon);

int flags = packInfo.applicationInfo.flags;

int uid = packInfo.applicationInfo.uid;

appInfo.setUid(uid);

if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
appInfo.setUserApp(false);//系统应用
} else {
appInfo.setUserApp(true);//用户应用
}
if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
appInfo.setInRom(false);
} else {
appInfo.setInRom(true);
}
String appName = packInfo.applicationInfo.loadLabel(pm).toString();
appInfo.setAppName(appName);
String packname = packInfo.packageName;
appInfo.setPackname(packname);
String version = packInfo.versionName;
appInfo.setVersion(version);
try {
mGetPackageSizeInfoMethod.invoke(mContext.getPackageManager(), new Object[]{
packname,
new IPackageStatsObserver.Stub() {
@Override
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException {
synchronized (appInfo) {
appInfo.setPkgSize(pStats.cacheSize + pStats.codeSize + pStats.dataSize);

}
}
}
});
} catch (Exception e) {
}

appinfos.add(appInfo);
}
return appinfos;
}

由于我只是一名初级开发人员,所以我不确定问题可能是什么。遇到此错误的特定手机使用的是 Android 6.0。我们将非常感谢帮助。非常感谢。

最佳答案

我认为这不是主要问题。您应该检查内存监视器是否存在内存不足异常。首先打开出现错误的Activity,然后按返回按钮检查是否有泄漏。
对于此异常,您可以采取一些措施。
在 Android list 中,您应该在应用程序标记下附加 largeheap = true。
您可以通过配置加载位图或可绘制文件并降低其空间

关于java - Android 6.0 上的 Android java.lang.OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42962054/

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