Android BitmapFactory.decodeFile重新启动应用程序

Android BitmapFactory.decodeFile重新启动应用程序,android,dictionary,bitmapfactory,Android,Dictionary,Bitmapfactory,我想把图像放入字典。图像的总大小为22 MB。这是我的密码 Dictionary<String, Bitmap> bmpCollection = new Hashtable<String, Bitmap>(); File filesDirectory = new File(Environment.getExternalStorageDirectory().getPath() + "/shared/Lenovo/Resimler/"); File[]

我想把
图像
放入
字典
。图像的总大小为22 MB。这是我的密码

    Dictionary<String, Bitmap> bmpCollection = new Hashtable<String, Bitmap>();
    File filesDirectory = new File(Environment.getExternalStorageDirectory().getPath() + "/shared/Lenovo/Resimler/");
    File[] files = filesDirectory.listFiles();
    for (File file:files)
    {
        try {
            Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
            String key = file.getName();
            key = key.substring(0,key.length()-4);
            bmpCollection.put(key,bmp);
        }
        catch (Exception ex)
        {
            int a = 0;
        }

    }
    return bmpCollection;
Dictionary bmpCollection=newhashtable();
File filesDirectory=新文件(Environment.getExternalStorageDirectory().getPath()+“/shared/Lenovo/Resimler/”;
File[]files=filesDirectory.listFiles();
用于(文件:文件)
{
试一试{
位图bmp=BitmapFactory.decodeFile(file.getAbsolutePath());
String key=file.getName();
key=key.substring(0,key.length()-4);
bmpCollection.put(key,bmp);
}
捕获(例外情况除外)
{
int a=0;
}
}
返回bmpCollection;

在第48个文件之前没有问题,但在该文件之后,当这一行工作时,程序重新启动自己
Bitmap bmp=BitmapFactory.decodeFile(file.getAbsolutePath())。它没有提到错误。不要触发
捕捉
。只需重新启动应用程序。可能是什么问题?我如何解决它?

可能是内存不足错误。尝试使用purgeable和samplesize位图选项解码以优化内存:

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inPurgeable = true;
bmOptions.inSampleSize = 2;
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), bmOptions);