2013-04-07 159 views
0

此代码崩溃。为什么?致命异常asynctask#2 doInBackground

@Override 
    protected String doInBackground(String... params) { 

     try { 
      image_compress = image_compress(changed_image); 

      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        1, 0)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        0, 1)); 


      array_image.add(Effects_change.doColorFilter((image_compress), 0, 
        1.2, 1.8)); 

      array_image.add(Effects_change.doGreyscale(image_compress)); 
      array_image.add(Effects_change.doGamma((image_compress), 0.8, 0.8, 
        0.8)); 
      array_image.add(Effects_change.doGamma((image_compress), 1.8, 1.8, 
        1.8)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 1.0, 
        0, 0)); 

      array_image.add(Effects_change.doColorFilter((image_compress), 0.5, 
        0.5, 0.5)); 
      array_image.add(Effects_change.doColorFilter((image_compress), 1.5, 
        1.5, 1.5)); 


      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 1.5, 0.6, 0.12)); 
      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 0.88, 1.45, 1.43)); 

      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 100, 1.2, 0.87, 1.8)); 
      array_image.add(Effects_change.decreaseColorDepth((image_compress), 
        32)); 

      array_image.add(Effects_change.decreaseColorDepth((image_compress), 
        120)); 

      array_image.add(Effects_change.applyReflection(image_compress)); 
      //array_image.add(Effects_change.applynewReflection(image_compress)); 
      array_image.add(Effects_change.applyFleaEffect(image_compress)); 

      array_image.add(Effects_change.sharpen((image_compress), 15)); 



      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 200, 0.50, 0.6, 0.20)); 
      array_image.add(Effects_change.createSepiaToningEffect(
        (image_compress), 150, 1.2, 0.97, 2.1)); 

      array_image.add(Effects_change.applyGaussianBlur(image_compress)); 
      array_image.add(Effects_change.applyBlackFilter(image_compress)); 
      array_image.add(Effects_change.applyMeanRemoval(image_compress)); 

      array_image.add(Effects_change.applySnowEffect(image_compress)); 

      array_image.add(Effects_change.smooth((image_compress), 8)); 
      array_image.add(Effects_change.CharcoalEffect(image_compress)); 

      array_image.add(Effects_change.tintImage((image_compress), 80)); 
      array_image.add(Effects_change.roundCorner((image_compress), 45)); 

      array_image.add(Effects_change.boost((image_compress), 1, 
        (float) 1.5)); 
      array_image.add(Effects_change.boost((image_compress), 2, 
        (float) 0.30)); 
      array_image.add(Effects_change.boost((image_compress), 3, 
        (float) 0.67)); 
      array_image.add(Effects_change.emboss(image_compress)); 

      array_image.add(Effects_change.boost((image_compress), 1, 
        (float) .50)); 

      array_image.add(Effects_change.boost((image_compress), 2, 
        (float) 0.10)); 
      array_image.add(Effects_change.boost((image_compress), 3, 
        (float) 1.5)); 
      array_image.add(Effects_change.engrave(image_compress)); 
      array_image.add(Effects_change.applyHueFilter((image_compress), 3)); 

      array_image.add(Effects_change 
        .changeToNegativeEffect(image_compress)); 
      array_image.add(Effects_change.SketchImage(image_compress)); 

      array_image.add(Effects_change.doColorFilter(image_compress, 1.8, 1.2, 1)); 


      array_image.add(Effects_change.tintImage((image_compress), 180)); 

      array_image.add(Effects_change.applySaturationFilter(image_compress, 2)); 

      array_image.add(Effects_change.createContrast(image_compress, 100)); 

      array_image.add(Effects_change.applySaturationFilter((image_compress), 90)); 
      // array_image.add(Effects_change.posterize(image_compress, 10)); 

      // setProgress(""+(int)((total*100)/lenghtOfFile)); 

     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     //array_image.add(Effects_change.setSepiaColorFilter(image_compress)); 

     return null; 
    } 

    @Override 
    public void onPostExecute(String result) { 
     super.onPostExecute(result); 

     g.setAdapter(new ImageAdapter(Image_add_effects.this)); 
     g.setOnItemSelectedListener(Image_add_effects.this); 

     try { 
      pb.dismiss(); 
      pb=null; 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 
    } 

} 

这是日志

04-07 22:36:08.450: W/dalvikvm(18429): threadid=13: thread exiting with uncaught exception(group=0x41fe82a0) 
04-07 22:36:08.450: E/AndroidRuntime(18429): FATAL EXCEPTION: AsyncTask #2 
04-07 22:36:08.450: E/AndroidRuntime(18429): java.lang.RuntimeException: An error occured while executing doInBackground() 
04-07 22:36:08.450: E/AndroidRuntime(18429): at android.os.AsyncTask$3.done(AsyncTask.java:299) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.lang.Thread.run(Thread.java:856) 
04-07 22:36:08.450: E/AndroidRuntime(18429): Caused by: java.lang.OutOfMemoryError 

我怎样才能解决这个问题?

回答

0

原因是java.lang.OutOfMemoryError这意味着您的计算会吃太多的RAM。

然而,不知道你在做什么,很难说出什么原因导致了错误。可能你创建了太多的图像/位图。

这里是多少RAM,availiable你的应用程序的信息:https://stackoverflow.com/a/9940415/247013

观念调查:

  • 化妆用的Bitmap.recycle() - 调用它时,你并不需要一个处理位图
  • 尽量不要将图像存储在RAM中,而是将其保存到文件中
  • 看起来您正尝试预先为任何可能的效果预先创建图像 - 考虑重新设计 - 执行一项有效只有当用户明确要求时(按需)。
+0

谢谢,我找出了由位图图像大小引起的问题 – 2013-04-08 16:15:33

相关问题