如何删除该例外,这个例外的有什么意义呢? [英] How Remove This Exception And What's meaning of this Exception?

查看:132
本文介绍了如何删除该例外,这个例外的有什么意义呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的applicatin occure此异常请建议我如何纠正这种异常: -
我曾经尝试过在ImageLoader的code键更改为,但不是成功的。

  //德code图像尺寸
        BitmapFactory.Options O =新BitmapFactory.Options();
        o.inJustDe codeBounds = TRUE;
        BitmapFactory.de codeStream(新的FileInputStream(F),空,O);
        / *
         * options.inJustDe codeBounds = TRUE;
BitmapFactory.de codeResource(RES,渣油,期权);//计算inSampleSize
options.inSampleSize = calculateInSampleSize(选项,reqWidth,reqHeight);//德code位与inSampleSize集
options.inJustDe codeBounds = FALSE;
返回BitmapFactory.de codeResource(RES,渣油,期权);         *
         *
         *
         * * /
     //计算inSampleSize
        o.inSampleSize = calculateInSampleSize(邻,100,100);
        o.inJustDe codeBounds = FALSE;
        //找到正确的比例值。它应该是2的幂。
       //最终诠释REQUIRED_SIZE = 70;
        // INT width_tmp = o.outWidth,height_tmp = o.outHeight;
  // int标= 1;
//而(真){
 //如果(width_tmp / 2'; REQUIRED_SIZE || height_tmp / 2版; REQUIRED_SIZE)
 //突破;
 // width_tmp / = 2;
 // height_tmp / = 2;
//规模* = 2;
 //}               //德code。与inSampleSize
           // BitmapFactory.Options O2 =新BitmapFactory.Options();
              //
            // o2.inSampleSize = 2;        返回BitmapFactory.de codeStream(新的FileInputStream(F),NULL,NULL);

由于异常在本节occure什么错在上面code ...

  10月6日至28日:53:36.676:E / dalvikvm堆(595):960000字节外部分配太大,这一进程。
  十月6日至28日:53:36.806:E / GraphicsJNI(595):虚拟机不会让我们分配960000字节
 十月6日至28日:53:36.836:E / AndroidRuntime(595):致命异常:AsyncTask的#1
十月6日至28日:53:36.836:E / AndroidRuntime(595):了java.lang.RuntimeException:执行doInBackground发生错误()
 十月6日至28日:53:36.836:E / AndroidRuntime(595):在android.os.AsyncTask $ 3.done(AsyncTask.java:200)
 十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.FutureTask中$ Sync.innerSetException(FutureTask.java:274)
 十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:308)
   十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.FutureTask.run(FutureTask.java:138)
十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:581)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.lang.Thread.run(Thread.java:1019)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):java.lang.OutOfMemoryError:产生的原因位图大小超过VM预算
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在android.graphics.BitmapFactory.nativeDe codeStream(本机方法)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在android.graphics.BitmapFactory.de codeStream(BitmapFactory.java:470)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.utilities.ImageLoader.de codeFILE(ImageLoader.java:161)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.utilities.ImageLoader.getBitmap(ImageLoader.java:94)
    十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.handler.DetailPhotoHandler.imagefecher(DetailPhotoHandler.java:211)
   十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.handler.DetailPhotoHandler.characters(DetailPhotoHandler.java:153)
   十月6日至28日:53:36.836:E / AndroidRuntime(595):在org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:165)
   十月6日至28日:53:36.836:E / AndroidRuntime(595):在org.apache.harmony.xml.ExpatParser.appendBytes(本机方法)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在或g.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
 十月6日至28日:53:36.836:E / AndroidRuntime(595):在org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.home.PropertyDetail $ Photostask.doInBackground(PropertyDetail.java:1174)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在com.rentfaster.home.PropertyDetail $ Photostask.doInBackground(PropertyDetail.java:1)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在android.os.AsyncTask $ 2.call(AsyncTask.java:185)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:306)
  十月6日至28日:53:36.836:E / AndroidRuntime(595):... 4个


解决方案

您可以看到我的<一个href=\"http://stackoverflow.com/questions/10737582/bitmap-size-exceeds-vm-budget-error-android/10738115#10738115\">answer就同​​一问题。

如果你想要一些更多的帮助,请让我知道。

感谢您:)

更新:

您已经使用:

  BitmapFactory.de codeStream(新的FileInputStream(F),空,O);

此方法创建一个位图并返回位图,你不要再追了位图。

您应该使用这样的:

  BMP位图= BitmapFactory.de codeStream(新的FileInputStream(F),空,O);

您应该首先创建的所有选项,然后调用德codeStream()方法。没有调用此方法后创建选项的效果。

您已经使用的选项,但总是尝试使用所有可能的选项,您可以使用,像下面这样:

  options.inScaled = TRUE;
options.inPurgeable = TRUE;//将图像缩放到1/8
options.inSampleSize = 8;

随时拨打 bitmap.recycle() 方式,只要你已经使用位图。

如果所有这些解决方案行不通,那么我建议,使用为Eclipse MAT 插件,因为,肯定u'd可以在你的$内存泄漏C $角

In My applicatin occure this exception please suggest me How I can Rectify this Exception:- I have been Tried to change in Imageloader code as but that not success.

 //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);

What wrong in above code because Exception occure in this section...

  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

解决方案

You can see my answer on the same issue.

If you want some more help, please let me know.

Thank you :)

UPDATE:

You have used:

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

This method creates a bitmap and returns the bitmap, you are not catching that bitmap.

you should use something like:

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

You should create all the options first and then call the decodeStream() method. There is no effect of creating options after calling this method.

You have used options, but always try to use all possible options that you can use, like following:

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

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

Always call the bitmap.recycle() method as soon as you have used bitmap.

If all these solutions does not work, then as I have suggested, use MAT for eclipse plugin, because, certainly u'd be having a memory leak in your code.

这篇关于如何删除该例外,这个例外的有什么意义呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆