如何删除此异常以及此异常的含义是什么?

时间:2012-06-28 05:29:28

标签: android exception

在我的应用程序中发生此异常请建议我如何纠正此例外: - 我一直试图改变Imageloader代码但不成功。

 //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);
        /*
         *  options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);

         * 
         * 
         * 
         * */
     // Calculate inSampleSize
        o.inSampleSize = calculateInSampleSize(o,100,100);
        o.inJustDecodeBounds = false;
        //Find the correct scale value. It should be the power of 2.
       // final int REQUIRED_SIZE=70;
        //int width_tmp=o.outWidth, height_tmp=o.outHeight;
  //            int scale=1;
//            while(true){
 //                if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
 //                    break;
 //                width_tmp/=2;
 //                height_tmp/=2;
//                scale*=2;
 //            }

               //decode with inSampleSize
           //            BitmapFactory.Options o2 = new BitmapFactory.Options();
              //            
            //            o2.inSampleSize=2;

        return BitmapFactory.decodeStream(new FileInputStream(f), null, null);

上面的代码有什么问题,因为本节中发生了异常...

  06-28 10:53:36.676: E/dalvikvm-heap(595): 960000-byte external allocation too large for this process.
  06-28 10:53:36.806: E/GraphicsJNI(595): VM won't let us allocate 960000 bytes
 06-28 10:53:36.836: E/AndroidRuntime(595): FATAL EXCEPTION: AsyncTask #1
06-28 10:53:36.836: E/AndroidRuntime(595): java.lang.RuntimeException: An error occured while executing doInBackground()
 06-28 10:53:36.836: E/AndroidRuntime(595):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
 06-28 10:53:36.836: E/AndroidRuntime(595):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
 06-28 10:53:36.836: E/AndroidRuntime(595):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
   06-28 10:53:36.836: E/AndroidRuntime(595):   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-28 10:53:36.836: E/AndroidRuntime(595):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at java.lang.Thread.run(Thread.java:1019)
    06-28 10:53:36.836: E/AndroidRuntime(595): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    06-28 10:53:36.836: E/AndroidRuntime(595):  at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at com.rentfaster.utilities.ImageLoader.decodeFile(ImageLoader.java:161)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at com.rentfaster.utilities.ImageLoader.getBitmap(ImageLoader.java:94)
    06-28 10:53:36.836: E/AndroidRuntime(595):  at com.rentfaster.handler.DetailPhotoHandler.imagefecher(DetailPhotoHandler.java:211)
   06-28 10:53:36.836: E/AndroidRuntime(595):   at com.rentfaster.handler.DetailPhotoHandler.characters(DetailPhotoHandler.java:153)
   06-28 10:53:36.836: E/AndroidRuntime(595):   at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:165)
   06-28 10:53:36.836: E/AndroidRuntime(595):   at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at or g.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
 06-28 10:53:36.836: E/AndroidRuntime(595):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at com.rentfaster.home.PropertyDetail$Photostask.doInBackground(PropertyDetail.java:1174)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at com.rentfaster.home.PropertyDetail$Photostask.doInBackground(PropertyDetail.java:1)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
  06-28 10:53:36.836: E/AndroidRuntime(595):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  06-28 10:53:36.836: E/AndroidRuntime(595):    ... 4 more

3 个答案:

答案 0 :(得分:1)

您可以在同一问题上看到我的answer

如果您需要更多帮助,请告诉我们。

谢谢:)

<强>更新

您使用过:

BitmapFactory.decodeStream(new FileInputStream(f),null,o);

这个方法创建一个位图并返回位图,你没有抓住那个位图。

你应该使用类似的东西:

Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(f),null,o);

您应首先创建所有选项,然后调用decodeStream()方法。调用此方法后,无法创建选项。

您已使用过选项,但始终尝试使用可以使用的所有选项,如下所示:

options.inScaled = true;
options.inPurgeable = true;

// to scale the image to 1/8
options.inSampleSize = 8;

使用位图后,请务必立即调用 bitmap.recycle() 方法。

如果所有这些解决方案都不起作用,那么就像我建议的那样,使用MAT for eclipse插件,因为你的代码肯定会有内存泄漏。

答案 1 :(得分:0)

因为这个原因发生错误......

06-28 10:53:36.836:E / AndroidRuntime(595):引起:java.lang.OutOfMemoryError:位图大小超过VM预算

检查link

link2

它可以帮到你。

由于

答案 2 :(得分:0)

听起来你有内存泄漏,你的活动中的位图没有被垃圾收集器正确释放,因为它们已经交叉引用了它们的活动。尝试通过adb shell dumpsys meminfo命令

监视堆使用情况