2

我正在尝试将一些图像从 SDCard 中的文件夹加载到我的 ImageSwitcher 上。我正在创建一个可运行并在循环中执行,以便图像一个接一个地显示。

 final ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
             imageSwitcher.postDelayed(
                     new Runnable() {

                         @Override
                         public void run() {
                             i++;

                             File dir = new File("/sdcard/Wallpapers/My Wallpapers");
                             final File file[]=dir.listFiles();

                                 imageSwitcher.setImageURI(Uri.fromFile(file[i]));
                                 imageSwitcher.postDelayed(this, 2000); 


                         }
                     },
                     2000);

一些图像工作正常,一段时间后应用程序由于“内存不足”异常而崩溃。

我尝试通过将这段代码放在下面来解决内存问题:

“imageSwitcher.postDelayed(这个,2000);”

这是我放在那里的代码:

ImageView v = (ImageView)imageSwitcher.getNextView(); 
BitmapDrawable bd = (BitmapDrawable) v.getDrawable(); 
Bitmap b = bd.getBitmap();
b.recycle();

此强制以 Nullpointer 异常关闭应用程序。

我想知道如何处理这个内存问题..或者我哪里出错了?

4

0 回答 0